访问对应于图形区域的位图像素。 [英] Accessing bitmap pixels that correspond to a graphics region.

查看:96
本文介绍了访问对应于图形区域的位图像素。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想首先说明我不是专业程序员,而且经常使用我在Code等网站上找到的例子项目。可能是我从错误的角度接近这个,所以请你认为合适的评论。



背景

出于某些分析目的,我需要计算处理后的位图图像的黑色与白色像素的比率。但是,并不是整个位图都很重要。感兴趣的区域各不相同,因此我需要一种photoshop方式来选择(和排除)图像的不同部分。



方法

处理后的位图加载到PictureBox派生对象中,并通过鼠标事件捕获选择。选择存储在o.a.矩形列表,用于通过union和exclude组装Graphics.Region对象。通过直接绘制到PictureBox对象的覆盖OnPaint事件来可视化区域和形状。



到目前为止,非常好。

我可以通过输入不安全的代码或通过GetPixel()方法访问位图中的单独像素,并且我有一个区域代表我感兴趣的像素。但是,我找不到一种方法来过滤掉与所选区域对应的像素。



有没有办法只迭代我位图中对应的像素与该地区?



非常感谢任何帮助。



谢谢。

Hello all,

I would like to start off with stating that i'm not a professional programmer, and often work from examples I find on sites like Code Project. It might be that i'm approaching this from the wrong angle, so please comment as you see fit.

Background
For some analysis purpose I need to calculate the ratio of black vs white pixels of a processed bitmap image. However, not the entire bitmap is of interest. The region of interest varies, therefore I need a photoshop kind of way of selecting (and excluding) different portions of the image.

Approach
The processed bitmap is loaded in a PictureBox derived object and selections are catched through mouse events. The selections are stored in o.a. a rectangle list, which is used to assemble a Graphics.Region object through union and exclude. The region and shapes are visualised by drawing directly into the overrided OnPaint event of the PictureBox object.

So far, so good.
I'm able to access separate pixels in a bitmap by entering unsafe code or through the GetPixel() method and I have a region that represents my pixels of interest. However, I cannot find a way to filter out the pixels that correspond to the selected region.

Is there any way of iterating only through the pixels in my bitmap that correspond with the region?

Any help is greatly appreciated.

Thanks.

推荐答案

对于任何感兴趣的人..



我通过创建一个Mask位图并将其填充为白色和区域来解决这个问题黑色。然后我可以迭代掩码位图像素以获得感兴趣的像素。没有完全填充白色像素在某种程度上无法正确读取。



解决方案实际上非常简单。这证明当你在它里面连续工作很多时间后退一步确实有帮助:)
For anyone interested..

I solved this by creating a "Mask" bitmap and filling it white and the region with black. I could then iterate the mask bitmap pixels to get pixels of interest. Without filling it completely white pixels are somehow not read correctly.

The solution was actually quite simple. This proves that stepping back when you are in it for many straight hours really does help :)


这篇关于访问对应于图形区域的位图像素。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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