By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,947 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

GDI+ Glass Table effect

P: n/a
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 ?
Jul 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
JezB,
Codeproject.com has several articles on "glass" and alpha-blending that may
be helpful in this area.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"JezB" wrote:
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 ?
Jul 7 '06 #2

P: n/a
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.RotateNoneFli pY);
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);
}

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:31**********************************@microsof t.com...
JezB,
Codeproject.com has several articles on "glass" and alpha-blending that
may
be helpful in this area.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"JezB" wrote:
>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 ?

Jul 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.