Click here to Skip to main content
15,919,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends I have converted an image to green part means i have used color filter concept and converted an image to green image now i want to convert green image to again original image.for example i want to do such that there is a progress bar when i move the prgress bar color of image is get changed when i put progress bar to original possion original color gets back.so how to do this please help me.Thanks
Posted
Comments
johannesnestler 11-Jan-12 8:44am    
some thoughts: Don't control this behaviour with an progressbar. And it's impossible to answer if you don't tell us how you stored the green image (was color information lost?) Show some code maybe?

1 solution

I think you mean you want to control the relative intensity of "green" with some kind of run-time adjustable control, like a TrackBar.

In any case, imho, you shoud always keep a "virgin" copy of the original full-color file around, whether you use any of the types of solutions suggested here !

If you are going to do this in code, then you are almost certainly going to want to examine the "relatively newer" ColorMatrix facility[^], and the ImageAttributes Class[^].

Or you may want to use what are now older techniques involving the Paint operation and LockBits: literally looping through every pixel and modifying its alpha value.

There are articles on CP showing how to accomplish this, and I strongly suggest you search CP for them. Such as:[^] ... and ... "Making Transparent Controls with C# and .NET 3.5"[^].

A "quick and dirty" solution would be to create two bit-maps: start with the original image: open it in GIMP or PhotoShop, then ... for example in PhotoShop ... use the Image/Adjustments/Saturation dialog, check the "colorize" button, and then make the image very dark greenish.

Obviously, in your project: you'll want to put the "greened image" on top of the original full-color, and then alter its opacity value with a TrackBar, or whatever, to control how "green" it is.

But, the tricky question is: in what Container should the second (greened) image be ! Or, the first full-color image ?

Since a PictureBox does not support opacity directly: see this discussion for how to achieve that: "C# Opacity Of Picturebox"[^].

For using Panels to achieve transparency, see this: see Bob Powell's old, but good, article: [^]

For using transparency/opacity with UserControls: the same CP resources linked to above will give you some guidelines. Also see this MSDN discussion:[^].

Finally, while I am generally against the idea of putting Forms inside ... or "over" other Forms in general; you could put the "greened" picture in its own borderless Form (as BackGroundImage): then: in the Main Form (with the TrackBar):

1. create a new instance of the second Form.

2. set the 'Owner Property of the second Form to the Main Form ... "independent" opacity will NOT work for the second Form if you add it to the ControlCollection of the Main Form !

3. Do the right thing in Main Form load event to position the second greened form exactly over the first colored Form. Your Main Form Load event might then look like this:
C#
// define a class scoped variable for the second Form
private Form2 f2;
//
Form1_Load(object sender, EventArgs e)
 {
     f2 = new Form2();
     f2.Owner = this;
     f2.Show();
     // note the need to translate co-ordinates here
     f2.Location = PointToScreen(ColorPictureBox.Location);
     f2.BringToFront();
 }
Then you can use the Main FormTrackBar change Value to set the opacity of the greened form:
C#
private void trackBar1_Scroll(object sender, EventArgs e)
{
    // note the need to use Convert.ToDouble here !
    f2.Opacity = Convert.ToDouble(trackBar1.Value) / 100.0;
}
This will work ... but ...

The question you might want to really evaluate carefully here is: do you want build a one-off solution for making a picture "greened," asap: or, do you want to master a set of techniques that could be generally useful in the future for doing all kinds of bitmap manipulation ?

good luck, best, Bill
 
Share this answer
 
v2

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