Hi
I need to add a alpha channel to a bmp file. how can i do this in vb.net 2005?
I use this code to load a picure to a picturebox, draw on it and then save it.
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class Form1
Inherits System.Windows.Forms.Form
Private objBitmap As Bitmap
Private objGraphics As Graphics
Private strImgFile As String = "test.bmp"
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
objBitmap = New Bitmap(200, 200, System.Drawing.Imaging.PixelFormat.Format24bppRgb)
objGraphics = Graphics.FromImage(objBitmap)
Dim img As Image = Image.FromFile(Environment.CurrentDirectory & "\" & "yukon.gif")
objGraphics.DrawImage(img, 0, 0)
End Sub
Dim path As New GraphicsPath
Dim prevPt As New Point(100, 100)
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.DrawPath(Pens.Black, path)
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
prevPt.X = e.X
prevPt.Y = e.Y
path.StartFigure()
End If
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim g As Graphics = PictureBox1.CreateGraphics
Dim currPt As Point = New Point(e.X, e.Y)
'g.DrawLine(Pens.Black, prevPt, currPt)
objGraphics.DrawLine(Pens.Black, prevPt, currPt)
path.AddLine(prevPt, currPt)
prevPt = currPt
PictureBox1.Image = objBitmap
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
If MessageBox.Show("Bild speichern als " & strImgFile & " ?", _
"Bild speichern?", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
objBitmap.Save(strImgFile, System.Drawing.Imaging.ImageFormat.Bmp)
MessageBox.Show("Bild wurde gespeichert als " & strImgFile, _
"Bild wurde gespeichert", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
If MessageBox.Show( _
"Bilddatei mit dem Standardprogramm öffnen?", _
"Bilddatei öffnen?", MessageBoxButtons.YesNo, _
MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim p As Process = Process.Start("test.bmp")
End If
objBitmap.Dispose()
End If
End Sub