Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/06/2009, 02:52
Mirador
 
Fecha de Ingreso: abril-2007
Mensajes: 82
Antigüedad: 17 años, 10 meses
Puntos: 0
Establecer un color tranparente a un BMP

Buenas, llevo dias intentando crear una imagen con fondo tranaprente (de un colorkey) a partir de un bmp.

Lo que he hecho es cargar el bmp con un fondo azul en un picturebox, y en el evento paint tratarlo y finalmente pasarlo a un segundo picturebox pero ya con el fondo transparente... pero no hay manera >_<

Espero que me puedan ayudar!!

Código:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.PictureBox1.Image = Image.FromFile(Application.StartupPath & "\rock.bmp")
    End Sub

    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Try
            Dim bmp As Bitmap
            Dim bmpFinal As Bitmap
            Dim g As Graphics

            bmp = Me.PictureBox1.Image
            bmpFinal = New Bitmap(bmp.Width, bmp.Height)
            bmpFinal.MakeTransparent()

            g = Graphics.FromImage(bmpFinal)

            Dim attr As New ImageAttributes

            attr.SetColorKey(Color.Blue, Color.Blue)

            Dim dstRect As New Rectangle(0, 0, bmp.Width, bmp.Height)
            e.Graphics.DrawImage(bmp, dstRect, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, attr)

            'g.Dispose()
            'g.Save()

            Me.PictureBox2.Image = bmpFinal

        Catch ex As Exception
            Call MsgBox("Error: " & ex.Message & vbNewLine & "Traza: " & ex.StackTrace)
        End Try
    End Sub
Mi objetivo final es coger un archivo bmp de mi disco, y crear un gif con fondo transparente pasandole el colorkey (color de fondo), por si saben de alguna manera mas sencilla.

Saludos y espero que me puedan ayudar!