473,394 Members | 1,766 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,394 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 6499
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.