【发布时间】:2014-07-16 00:14:21
【问题描述】:
您好,谁能解释一下如何在java中将图像数据转换为字节数组,我正在尝试这样。我不需要在这里使用缓冲图像。
File file = new File("D:/img.jpg");
FileInputStream imageInFile = new FileInputStream(file);
byte imageData[] = new byte[(int) file.length()];
imageInFile.read(imageData);
【问题讨论】:
-
如果您想解码图像以便访问像素数据,通过
BufferedImage更容易 -
你能告诉我,byte[] 是什么?是从图像中读取的字节吗(就像您想从任何普通文件中读取字节一样)?还是你想从每个像素中获取字节?