使用java,图像被变换成BYTE排列、和该阵列为图象,远程传输的图片进行
代码例如以下:
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 block
e.printStackTrace();
}
}
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。