Von vielen Apple-Programmen bekannt ist der Effekt, dass Bilder auf einem spiegelnden Grund stehen, der einen Teil des Bildes reflektiert. Die folgende Funktion erzeugt genau diesen Effekt.
/// <summary>
/// Lets appear a picture standing on a reflecting ground.
/// </summary>
/// <param name="source">Image to apply effect to</param>
/// <param name="height">Height of the reflection (percentage)</param>
/// <param name="startTransparency">
/// transparency the effect starts with
/// </param>
/// <param name="BackgroundColor">Color of the ground</param>
/// <returns>a bitmap with the desired effect</returns>
private Bitmap ReflectingGround(Image source, byte height,
byte startTransparency, Color BackgroundColor)
{
// height needed for the shadow
int shadowHeight = Convert.ToInt32(
Convert.ToDouble(height) / 100 * source.Height);
// create new bitmap for the generated picture
Bitmap myBitmap = new Bitmap(source.Width,
source.Height + shadowHeight);
Graphics myGraphics = Graphics.FromImage(myBitmap);
// draw the source image
myGraphics.DrawImage(source, 0, 0);
// flip the source image and draw it below the source image
Image flipped = (Image)source.Clone();
flipped.RotateFlip(RotateFlipType.RotateNoneFlipY);
myGraphics.DrawImage(flipped, 0, source.Height);
// create gradient from semi-transparent to transparent over
// the flipped copy
Rectangle gradientRect = new Rectangle(0, source.Height,
source.Width, shadowHeight);
// create brush
System.Drawing.Drawing2D.LinearGradientBrush myBrush =
new System.Drawing.Drawing2D.LinearGradientBrush(
gradientRect,
Color.FromArgb(startTransparency, BackgroundColor),
Color.FromArgb(255, BackgroundColor),
System.Drawing.Drawing2D.LinearGradientMode.Vertical);
// draw gradient
myGraphics.FillRectangle(myBrush, gradientRect);
// return created bitmap
return myBitmap;
}
Kommentare zum Snippet