473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to add a Alpha channel to a picture? (vb.net2005)

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
Nov 30 '06 #1
0 1412

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sam Fisher | last post by:
Hi, I'm currently using a ListView- control in my VB.NET app, that shall look nice and therefore contains some 24 bit icons (plus 8 bit alpha channel). But the icons are not displayed correctly in...
1
by: Raymond Walsh | last post by:
Hello Please excuse me if this should've been posted elsewhere, but I couldn't find a GDI+ specific forum, and since the classes are part of ..NET, I thought maybe someone here would have more...
3
by: Bill English | last post by:
Does C# Support Alpha Channel Backgrounds? I have an image made in Photoshop, which has an alpha channel. I save it as a PNG file, then set the form's BG image to that file. Now it shows up fine...
0
by: morten skrubbeltrang | last post by:
According to KB article 822488 http://support.microsoft.com/default.aspx?scid=kb;en-us;822488 visual c# .net 2002 + 2003 has bug in rendering of alpha channel information when displaying a...
0
by: Hal Meyer | last post by:
Greetings. I'm using a PNG file with an alpha channel drop-shadow as a background on a borderless winform app. It renders fine at startup, but when I move the window (which is done with a...
2
by: Allan | last post by:
I've been trying to get this to work for days. I have a form which needs to be transparent (only the form background). On the form there are two images (32 bit PNGs) with alpha channel...
10
by: Lespaul36 | last post by:
I want to extract associated folder icons durring runtime and show them in a treeview control. The XP alpha channel messes that up. Is there a fix or a way to remove the alpha channel?
1
by: André Nogueira | last post by:
Hi there guys. I have some 32 Bits PNGs with an Alpha channel, and added them as icons on Toolbar buttons. However, the pixels affected by the Alpha channel (those that have some transparency)...
0
by: yxq | last post by:
Hello, I use the API ExtractIcon to get icon from Shell32, but the returned icon lost alpha channel, how get back the alpha channel? thank you. ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.