473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 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 6500
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Pat Keel | last post by:
Hi there, Im looking for a solution to draw a one pixel sized point to a graphics control. E.g. DrawLine(10,10, 11,11) draws 2 pixels, DrawLine(10,10, 10,10) has no effect. How to do? Thanks Pat
1
by: pei_world | last post by:
hi there, I am trying to create a image frame with multiple layers, and I will draw different objects on each layer in order to get an effect of deleting some part of object easily. At last, I...
8
by: Brian Basquille | last post by:
Hello all, Just a quick GDI+ related question for you all. I've three ellipses being drawn in my game. I'm trying to smoothen the edges of them out using anti-aliasing. Why is it that my puck...
5
by: jack | last post by:
In using GDI+ drawstring, if the string to be drawn is in rtf format, how do I make GDI+ to recognize the rtf attributes. In other words, how do I draw one string in GDI+ , within which the...
5
by: John Rugo | last post by:
Hi All, I am using VB.NET and GDI+ to handle Gradient Brush effects. I am using this for both Labels and Buttons. For the buttons I am changing the colors based on the mouse position of the...
0
by: Brian Keating | last post by:
hi there i've a test program that creates a treeview and destroys it over and over, i keep track of the gdi object count for the process and see if they are ok. However when i switch on...
7
by: Marcin Rzeznicki | last post by:
Hello, Do you think it is legitimate practice to mix GDI+ and GDI calls (via Get/ReleaseHDC()) in paint event of a control? I've heard there is possibility of performance loss while "locking"...
11
by: cty0000 | last post by:
I have some quiestion... I want to draw line,point,rectangles and etc... on the from So I code like this.. public update() { g = this.CreateGraphics(); g.FillRectangle(Brushes.White, x1,...
1
by: Chris Dunaway | last post by:
When working with GDI+, calling the CreateGraphics method to draw on a control has normally been frowned upon and it is always emphasized to dispose of pens and brushes and other GDI objects lest...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.