Dienstag, 4. Februar 2014
Fade mit der ColorMatrix.
OrginalText codeproject.com
OrginalText stackoverflow.com
OrginalText Josh Jordan
OrginalText codeproject.com
using System; using System.Drawing; using System.Drawing.Imaging; namespace ImageUtils { class ImageTransparency { public static Bitmap ChangeOpacity(Image img, float opacityvalue) { Bitmap bmp = new Bitmap(img.Width,img.Height); // Determining Width and Height of Source Image Graphics graphics = Graphics.FromImage(bmp); ColorMatrix colormatrix = new ColorMatrix(); colormatrix.Matrix33 = opacityvalue; ImageAttributes imgAttribute = new ImageAttributes(); imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttribute); graphics.Dispose(); // Releasing all resource used by graphics return bmp; } } }
pictureBox1.Image = ImageUtils.ImageTransparency.ChangeOpacity(Image.FromFile("filename"),opacityvalue);Fade mit Alpha.
OrginalText stackoverflow.com
int alpha = 0;
private void timer1_Tick(object sender, EventArgs e) { if (alpha++ < 255) { Image image = pictureBox1.Image; using (Graphics g = Graphics.FromImage(image)) { Pen pen = new Pen(Color.FromArgb(alpha, 255, 255, 255), image.Width); g.DrawLine(pen, -1, -1, image.Width, image.Height); g.Save(); } pictureBox1.Image = image; } else { timer1.Stop(); } }Fade mit Blur Effekt.
OrginalText Josh Jordan
public static Bitmap Fade(Bitmap image1, Bitmap image2, int opacity) { Bitmap newBmp = new Bitmap(Math.Min(image1.Width,image2.Width), Math.Min(image1.Height,image2.Height)); for (int i = 0; i < image1.Width & i < image2.Width; i++) { for (int j = 0; j < image1.Height & j < image2.Height; j++) { Color image1Pixel = image1.GetPixel(i, j), image2Pixel = image2.GetPixel(i, j); Color newColor = Color.FromArgb( (image1Pixel.R * opacity + image2Pixel.R * (100 - opacity) ) / 100, (image1Pixel.G * opacity + image2Pixel.G * (100 - opacity) ) / 100, (image1Pixel.B * opacity + image2Pixel.B * (100 - opacity) ) / 100); newBmp.SetPixel(i, j, newColor); } } return newBmp;
int trans = 30; pictureBox1.Image = Fade(new Bitmap(imgOld), new Bitmap(imgNew), trans);
Kategorie: programmierung