位图中不同颜色的数量 [英] count of distinct colors in a bitmap

查看:76
本文介绍了位图中不同颜色的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

我是C#的新手.有没有可以让我对位图中的不同颜色进行计数的函数?列出所有这些不同颜色的函数怎么样?

非常感谢!

Hello.

I am VERY new to C#. Is there a function that will give me a count of the distinct colors in a bitmap? How about a function that lists all these distinct colors?

Many thanks!

推荐答案

一种慢速但确定的方法是获取位图中的每个像素并存储该像素的颜色.这样,您将可以获得构成位图的所有颜色.

在互联网上搜索,您应该获取一些样本以在位图上获取像素.
A slow but sure approach to this would be to get every pixel in the bitmap and store the color of this pixel. This way you will be able to get all colors that make your bitmap.

Search on the internet and you should get some samples to get a pixel on your bitmap.


我希望使用字节数组来实现这一点.我创建了字节数组,但是在检索RGB值时遇到了问题.我走错了路吗?谢谢!
I was hoping to do this with a byte array. I created the byte array but I''m having issues retrieving the RGB values. Am I on the wrong track? Thanks!


.Net框架中没有内置的功能可以为位图提供像这样的直方图数据.如果您使用的是 System.Drawing.Bitmap [ LockBits [ BitmapData [
There is no single function built in to the .Net framework to give you histogram data like this for a bitmap. If you are using the System.Drawing.Bitmap[^] class, you can use the LockBits[^] method to get an BitmapData[^] object with a pointer to the image data and all the information you need about how to access it.


这篇关于位图中不同颜色的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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