Sending the contents of a canvas to a Java server and saving it as an image

前端 未结 4 1588
眼角桃花
眼角桃花 2021-02-09 03:06

Okay, basically I\'ve developed a simple image upload system. The user selects a local image (using the HTML5 File / FileReader API) and has the ability to crop it before confir

4条回答
  •  清酒与你
    2021-02-09 03:44

    import java.awt.image.BufferedImage;
    import java.io.ByteArrayInputStream;
    import java.io.File;
    import javax.imageio.ImageIO;
    import javax.xml.bind.DatatypeConverter;
    
    public class test {
        public static void main (String[] args){
         try{
                // remove data:image/png;base64, and then take rest sting
                String img64 = "64 base image data here";
            byte[] decodedBytes = DatatypeConverter.parseBase64Binary(img64 );
            BufferedImage bfi = ImageIO.read(new ByteArrayInputStream(decodedBytes));    
            File outputfile = new File("saved.png");
            ImageIO.write(bfi , "png", outputfile);
            bfi.flush();
         }catch(Exception e)
             {  
              //Implement exception code    
         }
    
        }
    }
    

提交回复
热议问题