Use of BitBlt Function
If you are drawing a picture with Draw methods in the PictureBox or if you are editing a picture in the PictureBox and you want to save the changes, just use a Button named btnSave, and if you want to save the drawn image or edited image, use a Button named btnsavefile.
Give the name to the pictureBox pic and use the BitBlt function.
Function mypicture() As Bitmap
Then you can convert the Bitmap image to other formats also:
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.IO
Public Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _
hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _
Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _
hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As System.Int32) As Long
Public memoryImage As Bitmap
Public pathmemoryImage As Bitmap ' used for bitmap saving
Public myImage As Bitmap
Public Function mypicture() As Bitmap
Dim mygraphics As Graphics = pic.CreateGraphics()
Dim s As Size = pic.Size
myImage = New Bitmap(s.Width, s.Height, mygraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(myImage)
Dim dc1 As IntPtr = mygraphics.GetHdc
Dim dc2 As IntPtr = memoryGraphics.GetHdc
BitBlt(dc2, 0, 0, pic.ClientRectangle.Width, _
pic.ClientRectangle.Height, dc1, 0, 0, 13369376)
mygraphics.ReleaseHdc(dc1)
memoryGraphics.ReleaseHdc(dc2)
Return myImage
End Function
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
mypicture()
pic.Image = mypicture()
End Sub
Join the conversation! Your thoughts help the community grow.