Encrypt and decrypt pictures using base64

Source: Internet
Author: User

Import Java.awt.image.BufferedImage;      Import Java.io.ByteArrayInputStream;      Import Java.io.ByteArrayOutputStream;      Import Java.io.File;           Import java.io.IOException;           Import Javax.imageio.ImageIO;      Import Sun.misc.BASE64Decoder;           Import Sun.misc.BASE64Encoder;          public class Testimagebinary {static Base64encoder encoder = new Sun.misc.BASE64Encoder ();                    Static Base64decoder decoder = new Sun.misc.BASE64Decoder ();                            public static void Main (string[] args) {System.out.println (Getimagebinary ());          Base64stringtoimage (Getimagebinary ());                     } static String Getimagebinary () {file F = new File ("c://20090709442.jpg");              BufferedImage bi;                  try {bi = Imageio.read (f);                  Bytearrayoutputstream BAOs = new Bytearrayoutputstream ();        Imageio.write (BI, "JPG", BAOs);          byte[] bytes = Baos.tobytearray ();              Return Encoder.encodebuffer (bytes). Trim ();              } catch (IOException e) {e.printstacktrace ();          } return null; } static void Base64stringtoimage (String base64string) {try {byte[] Byte                                    S1 = Decoder.decodebuffer (base64string);                  Bytearrayinputstream Bais = new Bytearrayinputstream (bytes1);                  BufferedImage bi1 =imageio.read (Bais);              File W2 = new file ("C://qq.bmp");//Can be jpg,png,gif format imageio.write (bi1, "JPG", w2);//regardless of the output format picture, here do not need to change              } catch (IOException e) {e.printstacktrace ();    }          }           }

Encrypt and decrypt pictures using base64

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.