C# 中关于图片透明叠加问题 一幅图片叠加到另一幅图片上,但是这幅图象不是完全将原来的图象覆盖,而是能够部分的透过叠加的图象显示出来2幅图片均是 gif 透明另外就是我GIF透明图片中有的地方设置了 alpha 在程序里面调用的时候怎么显示不出来他的透明度,而是背景颜色,图片已经设置透明了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 看看下面的代码能不能帮你如何使用GDI+绘制GIF动画bool blAnimated = false;private System.Windows.Forms.Button animateButton;Bitmap animatedImg = new Bitmap(@"G:\My Documents\My Pictures\hy.gif");private void OnFrameChanged(object o, EventArgs e) {this.Invalidate();}private void animateButton_Click(object sender, System.EventArgs e){blAnimated = ! blAnimated;if(blAnimated)ImageAnimator.Animate(animatedImg, new EventHandler(OnFrameChanged));elseImageAnimator.StopAnimate(animatedImg, new EventHandler(OnFrameChanged));}private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e){ImageAnimator.UpdateFrames();e.Graphics.DrawImage(animatedImg, new Point(0,0));} 关注,我连设一个JPG的透明度的地方都没找到,郁闷 主要要设置第二张图片的ImageAttributes 中的ColorMatrix对象,写一个测试程序如下: //绘制半透明的图像 Graphics g = this.CreateGraphics(); g.Clear(this.BackColor); Rectangle rect = new Rectangle(20, 20, 200, 100); OpenFileDialog opnDlg = new OpenFileDialog(); opnDlg.Filter = "All Image files|*.bmp;*.gif;*.jpg;*.ico;" + "*.emf;*.wmf|Bitmap files(*.bmp;*.gif;*.jpg;" + "*.ico)|*.bmp;*.gif;*.jpg;*.ico|" + "Meta Files(*.emf;*.wmf;*.png)*|*.emf;*.wmf;*.png"; opnDlg.Title = "ImageViewer: Open Image File"; opnDlg.ShowHelp = true; if (opnDlg.ShowDialog() == DialogResult.OK) { Bitmap bitmap = new Bitmap(opnDlg.FileName); float[][] ptsArray = { new float[] {1,0,0,0,0}, new float[] {0,1,0,0,0}, new float[] {0,0,1,0,0}, new float[] {0,0,0,0.5f,0}, new float[] {1,0,0,0,1} }; ColorMatrix clrMatrix = new ColorMatrix(ptsArray); if (clrMatrix.Matrix34 <= 0.5) { clrMatrix.Matrix34 = 0.8f; clrMatrix.Matrix11 = 0.3f; } ImageAttributes imgAttributes = new ImageAttributes(); imgAttributes.SetColorMatrices(clrMatrix,clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); g.FillRectangle(Brushes.Red, rect); rect.Y += 120; g.FillEllipse(Brushes.Black, rect); g.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, imgAttributes); g.Dispose(); } .net向存储过程传递datetime类型参数有问题 ExecuteReader()查询不到第一条数据 线程调用方法,如何判断该方法正在执行 DataGridView 控件列如何定制成日历控件.... 求助:删除XML中结点问题 MessageBox参数问题 DataView绑定技术 用浏览器打开word文档,怎么避免提示 编写资源管理器求助! 让我们大家一起来声讨TOP吧!支持被裁的同志们 如何固定MDI窗体中的工具栏 请问:如何获得窗体中某控件在屏幕上的绝对位置
如何使用GDI+绘制GIF动画
bool blAnimated = false;
private System.Windows.Forms.Button animateButton;
Bitmap animatedImg = new Bitmap(@"G:\My Documents\My Pictures\hy.gif");
private void OnFrameChanged(object o, EventArgs e)
{
this.Invalidate();
}
private void animateButton_Click(object sender, System.EventArgs e)
{
blAnimated = ! blAnimated;
if(blAnimated)
ImageAnimator.Animate(animatedImg, new EventHandler(OnFrameChanged));
else
ImageAnimator.StopAnimate(animatedImg, new EventHandler(OnFrameChanged));
}private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
ImageAnimator.UpdateFrames();
e.Graphics.DrawImage(animatedImg, new Point(0,0));
}
//绘制半透明的图像
Graphics g = this.CreateGraphics();
g.Clear(this.BackColor);
Rectangle rect = new Rectangle(20, 20, 200, 100);
OpenFileDialog opnDlg = new OpenFileDialog();
opnDlg.Filter = "All Image files|*.bmp;*.gif;*.jpg;*.ico;" +
"*.emf;*.wmf|Bitmap files(*.bmp;*.gif;*.jpg;" +
"*.ico)|*.bmp;*.gif;*.jpg;*.ico|" +
"Meta Files(*.emf;*.wmf;*.png)*|*.emf;*.wmf;*.png";
opnDlg.Title = "ImageViewer: Open Image File";
opnDlg.ShowHelp = true; if (opnDlg.ShowDialog() == DialogResult.OK)
{
Bitmap bitmap = new Bitmap(opnDlg.FileName);
float[][] ptsArray =
{
new float[] {1,0,0,0,0},
new float[] {0,1,0,0,0},
new float[] {0,0,1,0,0},
new float[] {0,0,0,0.5f,0},
new float[] {1,0,0,0,1}
}; ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
if (clrMatrix.Matrix34 <= 0.5)
{
clrMatrix.Matrix34 = 0.8f;
clrMatrix.Matrix11 = 0.3f;
}
ImageAttributes imgAttributes = new ImageAttributes();
imgAttributes.SetColorMatrices(clrMatrix,clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.FillRectangle(Brushes.Red, rect);
rect.Y += 120;
g.FillEllipse(Brushes.Black, rect);
g.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, bitmap.Width,
bitmap.Height, GraphicsUnit.Pixel, imgAttributes);
g.Dispose();
}