<图像处理>如何改变对比度&gt;错误 [英] image processing &gt; how to change the contrast &gt; Error

查看:108
本文介绍了<图像处理>如何改变对比度&gt;错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用TrackBar更改对比度:---------------

  private   void  contrast_Scroll( object  sender,EventArgs e)
{

// 创建过滤器
AForge.Imaging.Filters .ContrastCorrection filter = new ContrastCorrection(TrackBar1.Value);
// 应用过滤器

filter.ApplyInPlace(PictureBox1 。图片);
}



---------------错误::无法从System.Drawing.Image转换为AForge.Imaging .UnmanagedImage如何在源图像上应用过滤器? >>我是初学者! http://www.flickr.com/photos/92380688@N03/8395863084/in/photostream [ ^ ] >这里是pic

解决方案

不幸的是,解决方案1非常糟糕,无论它是否有效。它建议做的事情要比它们必须要复杂得多。



您的问题完全不同:它使用 PictureBox ,这是一个控件,而不是图像。

首先,整个成像库与控件无关。你这样做,你违反了UI和任何东西之间的基本隔离,例如成像。但这种控制特别糟糕,因为很多初学者试着把它坚持到不好的地方。经验法则是:永远不要使用它。



当然,没有这样的方法你需要o使用位图 BitmapData 。无需创建和 UnmanagedImage

http://www.aforgenet.com/framework/docs/html/1cc59f9a-2db9-e5e3-76b2-2d9bc84eab2d.htm [< a href =http://www.aforgenet.com/framework/docs/html/1cc59f9a-2db9-e5e3-76b2-2d9bc84eab2d.htmtarget =_ blanktitle =New Window> ^ ] 。



在您的情况下,我只需使用位图来表示图像。



为了让自己忘记困扰 PictureBox ,请查看我过去的答案:

如何从旧图纸中清除面板 [ ^ ],

在C#中绘制一个矩形 [ ^ ],

在图片框中附加图片 [ ^ ],

mdi子表单之间的绘制线 [ ^ ],

在面板上捕获绘图 [ ^ ],

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

如何加快我的vb.net程序? [的 ^ ]。



-SA






您需要将 PictureBox1.Image 转换为 AForge.Imaging。 UnmanagedImage 使用 FromManagedImage [ ^ ]功能:

<前郎=c#> private void contrast_Scroll( object sender,EventArgs e)
{

// 创建过滤器
AForge.Imaging.Filters.ContrastCorrection filter = new ContrastCorrection(TrackBar1.Value);
// 应用过滤器
AForge.Imaging.UnmanagedImage unmanagedImg = AForge。 Imaging.UnmanagedImage.FromManagedImage((位图)PictureBox1.Image);
filter.ApplyInPlace(unmanagedImg);
PictureBox1.Image = unmanagedImg.ToManagedImage();
}


I want to change the contrast using a TrackBar : ---------------

private void contrast_Scroll(object sender, EventArgs e)
        {

            // create filter
            AForge.Imaging.Filters.ContrastCorrection filter = new ContrastCorrection(TrackBar1.Value);
            // apply the filter

            filter.ApplyInPlace(PictureBox1.Image);
        }


--------------- Error :: cannot convert from System.Drawing.Image to AForge.Imaging.UnmanagedImage How to apply the filter on the source image ?? >> I''m a beginner ! http://www.flickr.com/photos/92380688@N03/8395863084/in/photostream[^]"> here the pic

解决方案

Unfortunately, Solution 1 really bad, no matter if it works or not. It suggests to do thing much more complex than they have to be.

Your problem was completely different: it was using PictureBox, which is a control, not an image.
First of all, the whole imaging library has nothing to do with controls. It you do, you violate elementary isolation between UI and anything, imaging, for example. But this control is especially bad, because too many beginner try to stick it where it is no good. The rule of thumb is: never ever use it at all.

And of course, there is no such method. You need to work with either Bitmap or BitmapData. No need to go as far as to create and UnmanagedImage:
http://www.aforgenet.com/framework/docs/html/1cc59f9a-2db9-e5e3-76b2-2d9bc84eab2d.htm[^].

In your case, I would simply use Bitmap, to represent the image.

To help yourself to forget that haunting PictureBox, please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^],
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
How to speed up my vb.net application?[^].

—SA


Hi,

You need to convert PictureBox1.Image to a AForge.Imaging.UnmanagedImage using the FromManagedImage[^] function:

private void contrast_Scroll(object sender, EventArgs e)
{
 
// create filter
AForge.Imaging.Filters.ContrastCorrection filter = new ContrastCorrection(TrackBar1.Value);
// apply the filter
AForge.Imaging.UnmanagedImage unmanagedImg = AForge.Imaging.UnmanagedImage.FromManagedImage((Bitmap)PictureBox1.Image);
filter.ApplyInPlace(unmanagedImg);
PictureBox1.Image = unmanagedImg.ToManagedImage();
}


这篇关于<图像处理>如何改变对比度&gt;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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