472,119 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

GDI+ Glass Table effect

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
2 6453
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
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.

Similar topics

4 posts views Thread by Pat Keel | last post: by
1 post views Thread by pei_world | last post: by
8 posts views Thread by Brian Basquille | last post: by
5 posts views Thread by jack | last post: by
reply views Thread by Brian Keating | last post: by
7 posts views Thread by Marcin Rzeznicki | last post: by
11 posts views Thread by cty0000 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.