您的位置:首页 > 编程语言 > Java开发

java--照片和BYTE这些东西阵列

2015-07-09 08:18 513 查看
使用java,图像被变换成BYTE排列、和该阵列为图象,远程传输的图片进行

参考:/article/1898459.html

代码例如以下:

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();
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: