Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / August 2005



Tip: Looking for answers? Try searching our database.

Save PictureBox contents to a bitmap

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike L - 27 Aug 2005 01:10 GMT
On my form, I'm using a PictureBox control as a container. There are various
text boxes/picture boxes/etc. on the PictureBox. Is there code that will
save the contents of the PictureBox (just as it would appear to the user on
the screen) to a bitmap image?

Thanks!

Mike L
Karl E. Peterson - 27 Aug 2005 01:21 GMT
> On my form, I'm using a PictureBox control as a container. There are
> various text boxes/picture boxes/etc. on the PictureBox. Is there
> code that will save the contents of the PictureBox (just as it would
> appear to the user on the screen) to a bitmap image?

Run SavePicture against the return of one of the functions exposed here:

 How To Capture and Print the Screen, a Form, or Any Window
 http://support.microsoft.com/kb/q161299/

Signature

Working Without a .NET?
http://classicvb.org/petition

Mike L - 27 Aug 2005 02:54 GMT
> Run SavePicture against the return of one of the functions exposed here:
>
>   How To Capture and Print the Screen, a Form, or Any Window
>   http://support.microsoft.com/kb/q161299/

The example worked, but when I put the module in my program, and added this
code to the form:

=======
Private Sub SaveBitmap_Click()
Set Picture1.Picture = CaptureClient(Me)
SavePicture Picture1.Picture, "C:\Test.bmp"
End Sub
=======

I get "Compile error: User-defined type not defined" when it gets to the
following code in the module:

=======
Private Declare Function OleCreatePictureIndirect _
Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, _
ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
=======
Steve Easton - 30 Aug 2005 23:36 GMT
Here's how I do it.  It's from a script I found on Randy Birch's site
and modified.
( I think it was Randy's site )

Create a second PictureBox, make sure it's the same size as the
original, and set visible to false.

Option Explicit
Private Declare Function SendMessage Lib "user32" Alias _
        "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
        ByVal wParam As Long, ByVal lParam As Long) As Long

     Private Const WM_PAINT = &HF
     Private Const WM_PRINT = &H317
     Private Const PRF_CLIENT = &H4&    ' Draw the window's client area
     Private Const PRF_CHILDREN = &H10& ' Draw all visible child
     Private Const PRF_OWNED = &H20&    ' Draw all owned windows

Private Sub Command1_Click()
'create and save image
Dim rv As Long
Picture2.AutoRedraw = True
rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
           PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Picture2.Picture = Picture2.Image
Picture2.AutoRedraw = False
SavePicture Picture2.Picture, "C:\path\to\file.bmp"

End Sub

It's what I use to save the image created by this utility:
http://www.95isalive.com/fixes/HitMeFP.htm

Signature

Steve
95isalive
This site is best viewed............
.......................with a computer

> On my form, I'm using a PictureBox control as a container. There are various
> text boxes/picture boxes/etc. on the PictureBox. Is there code that will
[quoted text clipped - 4 lines]
>
> Mike L
Mike L - 31 Aug 2005 01:30 GMT
Thanks! It worked, but other PictureBoxes on my form that have a background
color other than the form's background color (gray), the pictureboxes still
show up gray.

Any idea why this happens?
Steve Easton - 31 Aug 2005 12:33 GMT
It's hard to say without knowing what you're trying to do, but with
picture boxes you would need a command or event to change the background
of each one,

The example utility I showed you uses one picture box as the background,
and then 10 labels in a control array with the background set to
transparent.
That way the picture box background color shows behind the numbers in
the labels

Signature

Steve
95isalive
This site is best viewed............
.......................with a computer

> Thanks! It worked, but other PictureBoxes on my form that have a background
> color other than the form's background color (gray), the pictureboxes still
> show up gray.
>
> Any idea why this happens?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.