c# - 将原始灰度二进制文件转换为 JPEG

标签 c# java embedded jpeg grayscale

我有一个嵌入式系统的 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;

这是我的问题:(是的,复数)

  1. 您推荐使用什么应用程序将此源文件转换为 JPEG?
  2. GIMP 或 Paint 可以导入 CSV 数据文件吗?
  3. 如果我编写这个自定义应用程序,Java 库的用途是什么 JPEG?
  4. 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/

相关文章:

c# - 如何使用 C# 中的关联应用程序执行多个 ".ext"

java - openCMIS 本地绑定(bind) - JcrServiceFactory 与 jackRabbit 实现

java - 将坐标编码为二进制并压缩

c++ - 在 C 中将 Ascii 数字转换为十六进制数字

linux - webmin 是否适合在 debian 中基于 arm 的嵌入式系统上运行?

c# - Sonarqube for TFS 构建时响应错误 500

c# - 测试 WebApi Controller 时如何生成 Asp.net 用户身份

c# - 从 web 服务填充后将项目添加到 Telerik Ajax RadComboBox

java - 为什么没有调用run方法?

linker - 在 IAR Embedded Workbench 中自动配置链接器