我如何通过C#获取图像中的颜色 [英] how i can get color in image by c#

查看:569
本文介绍了我如何通过C#获取图像中的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有图片
此图片有颜色
我如何将此图像添加到字节数组
获取字节中的颜色数
感谢您的帮助.

i have image
this image has colors
how i can add this image to byte array
to get number of color in byte
thanks for any help

推荐答案

假设您将图像作为Bitmap 对象,则可以调用GetPixel.

请参阅 http://msdn.microsoft.com/en-us/library/system .drawing.bitmap.getpixel.aspx [ ^ ]
Assuming you have the image as a Bitmap object, you can call GetPixel.

See http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx[^]


设置一个HashSet并调用GetPixel()将其返回值添加到HashSet.

Setup a HashSet and call GetPixel() to add it''s return value to the HashSet.

private int CountImageColors(string fileName)
{
    HashSet<Color> colors = new HashSet<Color>();

    Bitmap bmp = new Bitmap(fileName);

    for (int x = 0; x < bmp.Size.Width; x++)
    {
        for (int y = 0; y > bmp.Size.Height; y++)
        {
            try
            {
                colors.Add(bmp.GetPixel(x, y));
            }
            catch (Exception)
            {
            }
        }
    }
    return colors.Count;
}


这篇关于我如何通过C#获取图像中的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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