Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to change the contrast using a TrackBar : ---------------
C#
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
Posted
Updated 30-Jan-13 9:08am
v7

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
 
Share this answer
 
Hi,

You need to convert PictureBox1.Image to a AForge.Imaging.UnmanagedImage using the FromManagedImage[^] function:
C#
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();
}
 
Share this answer
 
v2
Comments
Thomas Daniels 19-Jan-13 12:23pm    
I've updated my answer!
Thomas Daniels 20-Jan-13 8:51am    
You're welcome!
Sergey Alexandrovich Kryukov 19-Jan-13 18:32pm    
I just up-voted your answer, but only by my 3. Sorry. My initial vote was 1.

Formally, it should work, but the answer is so wrong and misleading, so it I would consider it as much worse then totally wrong, because it actually can do harm. If there is no answer at all, people keep looking for the solution; and there is the bad risk to end up with just the bad solution, which is usually worse than bad.

The problem is not only it's highly over-complicated, it is hiding the essence of the problem: OP uses PictureBox as it was a kind image. The main goal here is to eliminate this wrong way. I have a strong impression that you did not actually use the library, or did not use it essentially. Very often, your ability to read documentation better then OP works out well, but sorry, not at this time.

The purpose of UmnanagedImage is completely different and totally useless in this case. All one need is a Bitmap. But again, the main problem is misleading and hiding the real reason of the problem. I explained the rest in my answer, please see.

I'm trying to explain it is such detail because I don't want to look just as a baseless non-considerable down-voter, but want to collaborate with some members who are able to think, like you.

Thank you for understanding.
—SA
Thomas Daniels 20-Jan-13 8:59am    
I have a strong impression that you did not actually use the library, or did not use it essentially.
Yes, I didn't use the library, I was looking at the documentation.
The purpose of UmnanagedImage is completely different and totally useless in this case. All one need is a Bitmap. But again, the main problem is misleading and hiding the real reason of the problem. I explained the rest in my answer, please see.
I looked at your answer, and you're absolutely right. I've voted 5 for your answer.
Sergey Alexandrovich Kryukov 20-Jan-13 12:54pm    
Thank you very much.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900