我有一个嵌入式系统的 C 语言源代码,其中包含每像素 8 位灰度图像的数据数组。我负责编写软件文档,我想将此源代码转换为 JPEG(图像)文件。
这是一个代码示例:
const unsigned char grayscale_image[] = {
0, 0, 0, 0, 0, 0, 0, 74, 106, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 159,
159, 159, 159, 159, 159, 159, 159, 159, 159, 159, 146, 93, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
//...
};
const unsigned int height = 41;
const unsigned int width = 20;
这是我的问题:(是的,复数)
- 您推荐使用什么应用程序将此源文件转换为 JPEG?
- GIMP 或 Paint 可以导入 CSV 数据文件吗?
- 如果我编写这个自定义应用程序,Java 库的用途是什么 JPEG?
- C# 中有哪些库可以完成这项任务?
我有以下资源可供使用:MS Visio 2010、Gimp、Paint、Java、Eclipse、MS Visual Studio 2010 Professional、wxWidgets、wxFrameBuilder、Cygwin。
我可以使用 C#、Java、C 或 C++ 编写自定义应用程序。
感谢您的建议。
最佳答案
使用 java 的问题是将字节作为整数获取。在读入时,您需要转换为 int 以捕获大于 127 的值,因为 java 没有无符号字节。
int height=41;
int width=20;
int[] data = {...};
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
for ( int x = 0; x < width; x++ ) {
for ( int y = 0; y < height; y++ ) {
// fix this based on your rastering order
final int c = data[ y * width + x ];
// all of the components set to the same will be gray
bi.setRGB(x,y,new Color(c,c,c).getRGB() );
}
}
File out = new File("image.jpg");
ImageIO.write(bi, "jpg", out);
关于c# - 将原始灰度二进制文件转换为 JPEG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7080970/