Frage

Couldn't find an answer by myself so putting it out there,

Would it be possible to apply some kind of a darkish gradient shading at the top and/or bottom of an image dynamically in C# using VS 2010?

The effect would be such that the center of the image is untouched but the closer we get to the bottom or the top of the image, the darker it gets to give it a nice effect.

Regards,

War es hilfreich?

Lösung

Here's my solution for your question :

For Drawing a shadow like Gradient Over an Image we can use LinearGradientBrush from System.Drawing.Drawing2D to define a new brush , by using this brush and also Drawing/Filling a Rectangle on the top of the Image we can have the Shadow Effect over our Image

here's the result of using this method :

enter image description here

and here's a sample function which takes a bitmap and returns the Bitmap with Shadow Effect :

private Bitmap AddShodowOnTop(Bitmap bmp)
{
    Bitmap bmpGradient = new Bitmap(bmp);
    Graphics graphics = Graphics.FromImage(bmpGradient);

    LinearGradientBrush linearBrush = new LinearGradientBrush(
        new Point(0, 0),
        new Point(0, bmp.Height / 5),
        Color.FromArgb(130, 0, 0, 0),
        Color.FromArgb(0, 0, 0, 0));

    graphics.FillRectangle(linearBrush, 0, 0, bmp.Width, bmp.Height / 5);
    return bmpGradient;
}

For more Information , please take a look at :

Hope it Helps :)

Andere Tipps

You can create a gradient and combine it with original image.

Some useful resources: http://www.codeproject.com/Articles/6502/Transparency-Tutorial-with-C-Part-1 http://www.codeproject.com/Articles/20018/Gradients-made-easy

Probably the easiest scenario should be just combining black color with your image with given transparency - so the center of your image can be in original colors and with increasing distance from the center you can drop a shadow/make it darker.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top