Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
Posted 19-Jan-13 4:39am
Edited 30-Jan-13 9:08am
v7
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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();
}
  Permalink  
v2
Comments
ProgramFOX at 19-Jan-13 12:23pm
   
I've updated my answer!
ProgramFOX at 20-Jan-13 8:51am
   
You're welcome!
Sergey Alexandrovich Kryukov at 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
ProgramFOX at 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 at 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)

  Print Answers RSS
0 Maciej Los 450
1 OriginalGriff 403
2 CPallini 189
3 Sergey Alexandrovich Kryukov 189
4 CHill60 180
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 4,958
2 Maciej Los 3,269
3 Peter Leow 3,129
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100