標籤:
使用java,映像被變換成BYTE排列、和該陣列為圖象,遠程傳輸的圖片進行
參考:http://blog.csdn.net/huang9012/article/details/18241539
代碼例如以下:
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 {// 圖片轉換成 BYTE數組byte[] data = null;FileImageInputStream input = new FileImageInputStream(new File("d://7.jpg"));ByteArrayOutputStream output = new ByteArrayOutputStream();byte[] buf = new byte[1024];int numBytesRead = 0;while ((numBytesRead = 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", "素材名稱");//jo.put("picByte", data);////System.out.println(jo.toString());// byte數組 轉換成 圖片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();}}}
著作權聲明:本文部落格原創文章。部落格,未經同意,不得轉載。
java--照片和BYTE這些東西陣列