Click to See Complete Forum and Search --> : Urgent !!! How to Save a Image Drawn on a Picturebox Using hDc


October 9th, 1999, 10:49 AM
How to Save a Image Drawn on a Picturebox Using hDc / DrawIconEx to a file

Sterla

Aaron Young
October 9th, 1999, 07:47 PM
When drawing in the Image on the Picturebox, set the AutoRedraw property to True, this will copy the HDC Image to the Image of the Picturebox, you can then use Picture1 = Picture1.Image to make the Image a Persistent Graphic, allowing it to be Saved/Manipulated from the Picturebox.

Here's an example..

private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (byval hInst as Long, byval lpIconPath as string, lpiIcon as Long) as Long
private Declare Function DrawIcon Lib "user32" (byval hdc as Long, byval x as Long, byval y as Long, byval hIcon as Long) as Long

private Sub Command1_Click()
Dim lIcon as Long
on error GoTo LoadError
With CommonDialog1
.Filter = "All Files|*.*"
.CancelError = true
.ShowOpen
lIcon = ExtractAssociatedIcon(App.hInstance, .FileName, -1)
Caption = lIcon
Picture1.AutoRedraw = true
Call DrawIcon(Picture1.hdc, 0, 0, lIcon)
Picture1 = Picture1.Image
SavePicture Picture1, "C:\Image.bmp"
End With
LoadError:
End Sub




Aaron Young
Analyst Programmer
adyoung@win.bright.net
aarony@redwingsoftware.com