Give Picture a defined Shadow..
-
Hi , i have the following situation. I have a picturebox with a image in it (like a normal picture with a size of 48x48 pixel) now i wanna paint a shadow to a given direction an strengt. for example i say the light comes from left and the shadow should be right and 5 pixels big (something like the shadow functions in paintshop or photostudio) the pictures are png's with alphachannel. how can i resolve the above problem ? greetings
-
Hi , i have the following situation. I have a picturebox with a image in it (like a normal picture with a size of 48x48 pixel) now i wanna paint a shadow to a given direction an strengt. for example i say the light comes from left and the shadow should be right and 5 pixels big (something like the shadow functions in paintshop or photostudio) the pictures are png's with alphachannel. how can i resolve the above problem ? greetings
Shadowing the picture or the picture box?
-
Shadowing the picture or the picture box?
-
Hi , i have the following situation. I have a picturebox with a image in it (like a normal picture with a size of 48x48 pixel) now i wanna paint a shadow to a given direction an strengt. for example i say the light comes from left and the shadow should be right and 5 pixels big (something like the shadow functions in paintshop or photostudio) the pictures are png's with alphachannel. how can i resolve the above problem ? greetings
Personally, I would create a new control where you can control the painting procedures. In this control I would of course have the property of the image to shadow. Then in the paint event I would first draw the shadow of the image using ControlPaint.DrawImageDisabled(...) and then draw the slightly displaced image overtop of the shadow using the g.DrawImage routine (g is the Graphics object of the paint routine). I'll try to look for some code from a project that I just created that paints a shadowed image and post it. I would not even consider using shadows with a picturebox, it can only lead to trouble.
Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]
-
Personally, I would create a new control where you can control the painting procedures. In this control I would of course have the property of the image to shadow. Then in the paint event I would first draw the shadow of the image using ControlPaint.DrawImageDisabled(...) and then draw the slightly displaced image overtop of the shadow using the g.DrawImage routine (g is the Graphics object of the paint routine). I'll try to look for some code from a project that I just created that paints a shadowed image and post it. I would not even consider using shadows with a picturebox, it can only lead to trouble.
Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]
-
Hi Thomas, did you already post the code ? or could you send it me by mail. many greetings martin
This code is in C#, but I am sure that it can easily be translated. This is code that is contained in a screen saver presentation that paints 3 random images with a random quote specified in a particular directory:
public void DrawRandomImage(Graphics g, Rectangle rect) { if (usedIndexes.Count > currentImageIndex && bitmaps.Count >0) { if (showEffects) ControlPaint.DrawImageDisabled(g, bitmaps[usedIndexes[currentImageIndex]], rect.X + 5, rect.Y + 5, Color.Transparent); g.DrawImage(bitmaps[usedIndexes[currentImageIndex]], rect); currentImageIndex++; if (currentImageIndex == 3) currentImageIndex = 0; } else g.FillRectangle(new SolidBrush(Color.Black), rect); }
The variable bitmaps is an array of bitmaps that were read in from a specified directory. Basically replace the entire array with one image if you so choose. The two key parts of this code is:ControlPaint.DrawImageDisabled()
which will draw a grayscale image which then can be offsetted from the image drawn with theg.DrawImage
. If you need further explanation just ask. This explanation may seem a bit jumbled.Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios[^]