java--photos and byte arrays of these things

Source: Internet
Author: User

Using Java, the image is transformed into a byte arrangement, and the array is listed as an image, and a remotely transmitted picture is

Reference: http://blog.csdn.net/huang9012/article/details/18241539


The code is as follows:

Package Com.third.demo;import Java.io.bytearrayoutputstream;import Java.io.file;import Javax.imageio.stream.fileimageinputstream;import Javax.imageio.stream.fileimageoutputstream;import Org.json.jsonobject;public class Creatuploadjson {public static void Buildjson () throws Exception {//Picture converted to byte array byte[] D ATA = NULL; Fileimageinputstream input = new Fileimageinputstream (New File ("d://7.jpg")); Bytearrayoutputstream output = new Bytearrayoutputstream (); byte[] buf = new Byte[1024];int Numbytesread = 0;while ((numByt Esread = Input.read (BUF))! =-1) {output.write (buf, 0, numbytesread);} data = Output.tobytearray (); Output.close (); Input.close ();//jsonobject Jo = new Jsonobject ();//jo.put ("Agentid", "001" ),//jo.put ("Pictype", "1"),//jo.put ("Picname", "Material name"),//jo.put ("Picbyte", data),////SYSTEM.OUT.PRINTLN (    Jo.tostring ());//byte array converted to picture Fileimageoutputstream imageoutput = new Fileimageoutputstream (New File ("e://1.jpg"));    Imageoutput.write (data, 0, data.length); Imageoutput.close ();} /** *@param args */public static void main (string[] args) {try {Buildjson ();} catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();}}}


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

java--photos and byte arrays of these things

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.