Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

GDI+ Glass Table effect

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JezB - 07 Jul 2006 09:32 GMT
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 ?
Peter Bromberg [C# MVP] - 07 Jul 2006 12:10 GMT
JezB,
Codeproject.com has several articles on "glass" and alpha-blending that may
be helpful in this area.
Peter
Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> 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 - 07 Jul 2006 14:15 GMT
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);
}

> JezB,
> Codeproject.com has several articles on "glass" and alpha-blending that
[quoted text clipped - 7 lines]
>> coloured background) underneath so that the effect is like the object
>> sitting on a glass table. Any idea how I'd achieve this ?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.