我想将一幅GIF图像画到画板上,但是我想将GIF白色的区域透明的,应该如何来做,望高手指点!

解决方案 »

  1.   


    Public Class Form1    Private gif As Image = Nothing
        Private pic As PictureBox = Nothing    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            pic = New PictureBox With {.Dock = DockStyle.Fill, .BorderStyle = BorderStyle.FixedSingle}
            Me.Controls.Add(pic)        Using ofd As New OpenFileDialog With {.Filter = "*.gif|*.gif"}
                If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                    gif = Image.FromFile(ofd.FileName)
                    If ImageAnimator.CanAnimate(gif) Then
                        ImageAnimator.Animate(gif, New EventHandler(AddressOf gif_FrameChanged))
                    End If
                End If
            End Using
        End Sub    Private Sub gif_FrameChanged(ByVal sender As Object, ByVal e As EventArgs)
            ImageAnimator.UpdateFrames(gif)
            Using img As New Bitmap(gif)
                img.MakeTransparent(Color.White)
                pic.Image = img.Clone
            End Using
        End SubEnd Class
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {        private Image gif = null;
            private PictureBox pic = null;         public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                pic = new PictureBox { Dock = DockStyle.Fill, BorderStyle = BorderStyle.FixedSingle };
                this.Controls.Add(pic);            using (OpenFileDialog ofd = new OpenFileDialog { Filter = "*.gif|*.gif" })
                {
                    if (ofd.ShowDialog() ==   DialogResult.OK)
                    {
                        gif = Image.FromFile(ofd.FileName);
                        if (ImageAnimator.CanAnimate(gif))
                        {
                            ImageAnimator.Animate(gif, new EventHandler(gif_FrameChanged));
                        }
                    }
                }         }        private void gif_FrameChanged(object sender, EventArgs e)
            {
                ImageAnimator.UpdateFrames(gif);
                using (Bitmap img = new Bitmap(gif))
                {
                    img.MakeTransparent(Color.White);
                    pic.Image =(Image ) img.Clone();
                }
            }     }
    }
      

  3.   

    谢谢您的指点,现在的问题是我用的不是PictureBox,而是一个Panel,是在Pannel上绘图,用g.drawImage把一幅不是动画类型的gif画上去的,我试了一下用img.makeTransparent处理再画上之后,白色部分依然不透明,望能指点迷津!谢谢!