Leggere immagine esistente Bitmap()






Public Class Form1
' Load and display an image file.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim file_name As String = Application.StartupPath
If file_name.EndsWith("\bin\Debug") Then
file_name = file_name.Substring(0, file_name.LastIndexOf("\bin\Debug"))
End If
file_name &= "\Test.bmp"

' Load and display the image.

#If False Then
' Locks the file.

Dim bm As New Bitmap(file_name)
#Else
' Doesn't lock the file.

Dim original_bm As New Bitmap(file_name)
Dim bm As New Bitmap(original_bm.Width, original_bm.Height)
Using gr As Graphics = Graphics.FromImage(bm)
gr.DrawImageUnscaled(original_bm, 0, 0)
End Using
original_bm.Dispose()
original_bm = Nothing
#End If

' Display the image in a PictureBox.

picTest.Image = bm
Catch ex As Exception
MessageBox.Show("Error opening file" & vbCrLf & ex.Message)
End Try

End Sub
End Class










( leggereimmagineesistentebitmap.html )- by Paolo Puglisi - Modifica del 17/12/2023