一幅图片叠加到另一幅图片上,但是这幅图象不是完全将原来的图象覆盖,而是能够部分的透过叠加的图象显示出来2幅图片均是 gif 透明另外就是我GIF透明图片中有的地方设置了 alpha 在程序里面调用的时候怎么显示不出来他的透明度,而是背景颜色,图片已经设置透明了

解决方案 »

  1.   

    看看下面的代码能不能帮你
    如何使用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));
    }
      

  2.   

    关注,我连设一个JPG的透明度的地方都没找到,郁闷
      

  3.   

    主要要设置第二张图片的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();
                }