GDI+ Glass Table effect

  • Thread starter Thread starter JezB
  • Start date Start date
J

JezB

I have an image of an object which I display on a form. I'd like to use GDI+
to display a gradually-fading reflection of this image (on a white or
coloured background) underneath so that the effect is like the object
sitting on a glass table. Any idea how I'd achieve this ?
 
JezB,
Codeproject.com has several articles on "glass" and alpha-blending that may
be helpful in this area.
Peter
 
Thanks. Found something a bit like it, changed it, and now have a routine to
do it. For those that want it:

// Draw a reflection of an image
public static void DrawReflection
(
Graphics graphics, // the Graphics surface to paint on
Image image, // the Image to take a reflection of
Color backgroundColor, // the background colour
Rectangle destinationRectangle, // where to paint it (should be under a
painted object and the same size as it)
int reflectivity // 90 is recommended, 255 is full reflectivity, 0 is
none (so don't use it!)
)
{
// Crop the reflection to the bottom third (or depending on
reflectivity)
int reflectionHeight = (image.Height * reflectivity) / 255;
Image reflection = new Bitmap(image.Width, reflectionHeight);
Graphics g = Graphics.FromImage(reflection);
g.DrawImage(image, new Rectangle(0, 0, reflection.Width,
reflection.Height),
0, image.Height - reflection.Height, reflection.Width,
reflection.Height, GraphicsUnit.Pixel);
g.Dispose();

// then flip it
reflection.RotateFlip(RotateFlipType.RotateNoneFlipY);
Rectangle imageRect = new Rectangle(destinationRectangle.X,
destinationRectangle.Y,
destinationRectangle.Width, (destinationRectangle.Height *
reflectivity) / 255);

// Place it on the window.
graphics.DrawImage(reflection, imageRect);
// Create gradient brush depending on reflectivity
LinearGradientBrush brush = new LinearGradientBrush (imageRect,
Color.FromArgb(255 - reflectivity, backgroundColor),
backgroundColor,
90, false);

// And paint it over reflection image ...
graphics.FillRectangle(brush, imageRect);
}
 
Back
Top