C# - 如何将图像转换成8位色图像? [英] C# - How to convert an Image into an 8-bit color Image?

查看:629
本文介绍了C# - 如何将图像转换成8位色图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从文件加载一个PNG图像转换成其他设备(嵌入式编程)使用8位每像素的字节数组。

I need to convert a PNG Image loaded from a file into an 8 bit-per-pixel byte array used by another device (embedded programming).

我在复制逐个像素与16位颜色创造了一个新的图像 - Format16bppRgb565 ,但我需要 Format8bpp ,这是不是在.NET框架present。 (我不能使用 Format8bppIndexed 因为其他设备无法处理位图索引)

I'm copying over pixel by pixel into a new Image created with a 16-bit color - Format16bppRgb565, but I need Format8bpp, which is not present in the .NET Framework. (I cannot use Format8bppIndexed since the other device cannot handle indexed bitmaps)

 Bitmap img = new Bitmap(imgPath);
 Bitmap img8 = new Bitmap(imgW, imgH, PixelFormat.Format16bppRgb565);
 for (int I = 0; I <= img.Width - 1; I++) {
     for (int J = 0; J <= img.Height - 1; J++) {
         img8.SetPixel(I, J, img.GetPixel(I, J));
     }
 }

那么,如何可以将图像转换成每个像素的字节数组的8位?

So how can I convert an Image into an 8-bit per pixel byte array?


  • 我可以使用8位索引格式和提取字节? - Format8bppIndexed

  • 我可以通过减少32位色彩的R,G,B值,以8位计算像素颜色?

  • 是否有已经做了这个?
  • 一个C#库
  • 最简单的方法是创建一个新的8位位图,并绘制你的24位图像到它。 - 如何

  • Can I use the 8-bit indexed format and extract the bytes? - Format8bppIndexed
  • Can I calculate the pixel colors by reducing the 32-bit color R,G,B values to 8-bit?
  • Is there a C# library that does this already?
  • "The easiest way is to create a new 8 bit bitmap, and draw your 24 bit image onto it." - how?

推荐答案

虽然我不知道如何与普通的香草C#做到这一点,你可以使用的 FreeImage的项目库转换图像格式:

Although I'm not sure how to do it with plain vanilla C# you can use the FreeImage Project libraries to convert images formats:

FreeImage是一个开放源码库
  项目想谁开发
  支持流行的图形图像
  格式,如PNG,BMP,JPEG,TIFF和
  别人需要用今天的多媒体
  应用程序。 FreeImage是容易
  使用,快速,多线程安全的,
  与所有32位版本兼容
  Windows和跨平台(作品
  均与Linux和Mac OS X)。

FreeImage is an Open Source library project for developers who would like to support popular graphics image formats like PNG, BMP, JPEG, TIFF and others as needed by today's multimedia applications. FreeImage is easy to use, fast, multithreading safe, compatible with all 32-bit versions of Windows, and cross-platform (works both with Linux and Mac OS X).

它是用C ++编写,但是有可以使用.NET好包装。

It's written in C++ but has good .NET wrappers you can use.

这篇关于C# - 如何将图像转换成8位色图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆