将 RGB 图像转换为 RGB 16 位和 8 位 [英] Convert RGB image to RGB 16-bit and 8-bit

查看:209
本文介绍了将 RGB 图像转换为 RGB 16 位和 8 位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手程序员.是否有任何算法可以将图像转换为 16 位或 8 位?我在谷歌上没有找到它,我很绝望.

I'm a newbie programmer. Is there any algorithm to convert an image to 16-bit or 8-bit? I didn't find it on google, I'am desperate.

推荐答案

改为 16 位更容易.假设原始图像在 image 中,您可以简单地将其绘制到结果中.

Changing to 16 bit is the easier one. Assuming that the original image is in image, you can simply draw it into the result.

Bitmap result = new Bitmap(image.Width, image.Height, PixelFormat.Format16bppRgb565);
using (Graphics g = Graphics.FromImage(result))
{
    g.DrawImage(image, 0, 0, image.Width, image.Height);
}

不幸的是,这不适用于索引图像(带调色板的图像,最多 256 色).但是您可以在我的回答此处中找到解决方案,请参阅ConvertPixelFormat 方法.

Unfortunately, this does not work for indexed images (images with palette, up to 256 colors). But you can find a solution in my answer here, see the ConvertPixelFormat method.

这篇关于将 RGB 图像转换为 RGB 16 位和 8 位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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