Image,File与Byte转换
来源:互联网 发布:当代著名网络小说家 编辑:程序博客网 时间:2024/05/16 04:42
原址:http://superheizai.iteye.com/blog/630855
从byte[]转Image
public static byte[] getImageBytes(Image image) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData() };
imageLoader.save(baos, image.type);
byte[] imageByteArray = baos.toByteArray();
try {
baos.close();
} catch (Exception e) {
e.printStackTrace();
}
return imageByteArray;
}
从File转byte[]
public static byte[] getBytesFromFile(File f){
if (f == null){
return null;
}
try {
FileInputStream stream = new FileInputStream(f);
ByteArrayOutputStream out = new ByteArrayOutputStream(1000);
byte[] b = new byte[1000];
int n;
while ((n = stream.read(b)) != -1)
out.write(b, 0, n);
stream.close();
out.close();
return out.toByteArray();
} catch (IOException e){
}
return null;
}
从byte[]转file
public static File getFileFromBytes(byte[] b, String outputFile) ...{
BufferedOutputStream stream = null;
File file = null;
try ...{
file = new File(outputFile);
FileOutputStream fstream = new FileOutputStream(file);
stream = new BufferedOutputStream(fstream);
stream.write(b);
} catch (Exception e) ...{
e.printStackTrace();
} finally ...{
if (stream != null) ...{
try ...{
stream.close();
} catch (IOException e1) ...{
e1.printStackTrace();
}
}
}
return file;
}
- Image,File与Byte转换
- byte[]与Image Image与 byte[] 之间的转换
- image与byte数组的转换[引用]
- image与byte数组的转换
- image与byte数组的转换
- image与byte数组的转换
- image与byte数组的转换
- image与byte数组的转换
- C# byte[]与Image的相互转换
- image与byte数组的转换
- image与byte数组的转换
- C# byte[]与Image的相互转换
- Image与byte[]数组的相互转换
- byte数组与Image的相互转换
- Image 转换为 byte[]数组 与 byte[]数组转换为 Image
- image与byte数组的转换 (转载)
- [C#]image与byte数组的相互转换
- C#:Image与byte数组的相互转换
- wordpress的一些笔记
- 润乾建立超链的步骤
- struts2浅析
- 嵌入式微处理器的应用对比表:
- FLEX使用Model标签与定制as类
- Image,File与Byte转换
- 读《java编程思想》 字符串(13)
- 算法洗脑系列(8篇)——第六篇 回溯思想
- 嵌入式linux操作系统虚拟机nfs配置
- describe table_name 含义
- 安装完myeclipse出现qtdesigner (connection->initialization_error == NULL)错误
- ubuntu unmount command
- 轻松一刻
- source insight快捷键及使用技巧