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