Save the content from a picturebox in a jpeg, bmp or gif file.

Have a nice day.

I don't use speak english, but I gonna try.

I want to know how can I save the content inside a picturebox in a jpeg, bmp or gif file.
By example, in a picturebox I have 2 Textboxes, 1 usercontrol and 1 shape.
How can I create a image file (any format) including those controls inside the image?

Thanks!
nashualdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vb_elmarCommented:
VB (VB itself) can save the picture as a BMP (but not as JPG).

===============
Needs a Picturebox:
===============


ScaleMode = 3
Picture1.ScaleMode = 3: Picture1.DrawWidth = 3
Picture1.BorderStyle = 0: Picture1.BackColor = vbRed
Picture1.Picture = LoadPicture("C:\WINDOWS\Desktop\microangelo1.gif")

Picture1.AutoRedraw = True
Picture1.Width = 100: Picture1.Height = 100 'saved pic will be 100x100
Picture1.Line (0, 0)-(90, 90), vbGreen, B 'draw a 91x91 frame

Picture1.CurrentX = 0: Picture1.CurrentY = 0
Picture1.FontSize = 22: Picture1.Font = "Arial"
Picture1.CurrentX = 3: Picture1.CurrentY = 30
Picture1.Print "Hello" 'print 'Hello' to pos x,y

SavePicture Picture1.Image, "c:\windows\desktop\9Lmick.bmp" 'save to desktop as BMP
0
nashualdAuthor Commented:
Thanks vb_elmar, but I believe I did not explain myself very well.

I have two textboxes, an usercontrol and one shape inside a picturebox.
I would to know how to convert this arraingement into ain image file.

+-------------------------------------------------------------------
|   ___________________         _________________        |
|   |  TextBox1               |          |  UserControl1     |        |
|   ---------------------------         ------------------------       |  <--- PictureBox
|   ___________________                                               |
|   |  TextBox2              |                                                |
|   |                             |                                                |
|   ---------------------------                                              |
|                                                                                   |
|                                                                                   |
|   ---------------------------------       <-- Line (Shape control)
|                                                                                   |  
+-------------------------------------------------------------------

Thanks again.
0
vb_elmarCommented:
'needs a textbox inside a picbox
'and
'a second picbox

Private Declare Function BitBlt Lib "gdi32" _
                                    (ByVal hDestDC As Long, _
                                     ByVal x As Long, _
                                     ByVal y As Long, _
                                     ByVal nWidth As Long, _
                                     ByVal nHeight As Long, _
                                     ByVal hSrcDC As Long, _
                                     ByVal xSrc As Long, _
                                     ByVal ySrc As Long, _
                                     ByVal dwRop As Long) As Long

Private Sub Form_Activate()
AutoRedraw = True
DoEvents

Picture2.AutoRedraw = True 'destination pic box must have autoredraw

source1 = Picture1.hDC
destination1 = Picture2.hDC

destwidth = Picture2.Width / 15 'size of saved BMP
destheight = Picture2.Height / 15 'size of saved BMP
BitBlt destination1, 0, 0, destwidth, destheight, source1, 0, 0, vbSrcCopy
DoEvents

SavePicture Picture2.Image, "c:\windows\desktop\9Lmick.bmp" 'save to desktop as BMP

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nashualdAuthor Commented:
Thank you very much vb_elmar!

The code works very well, but I have noticed the following:
If, inside the picturebox, the size of a control is bigger than picturebox's height or picturebox's width, the control don't appear entirely into image file.
How can I look for all the objects inside the picturebox and include them in the image file, even if they aren't in the visible region of the picturebox?
Look the drawing:

+-------------------------------------------------------------------
|   ___________________         _________________        |
|   |  TextBox1               |          |  UserControl1     |        |
|   ---------------------------         ------------------------       |  <--- PictureBox
|   ___________________                                               |
|   |  TextBox2              |                                                |
|   |                             |                                                |
|   ---------------------------                                              |
|                                                                                   |
|                                                                                   |
|   ---------------------------------       <-- Line (Shape control)
|                                                                                   |  
|                                                           -------------------|--------------  
|                                                           |                      |                |
+-----------------------------------------------|-------------------                |
                                                             |                                       |    <-- Another control.
                                                             |                                       |
                                                             |                                       |
                                                            -----------------------------------
0
vb_elmarCommented:
BitBlt works with hdc's (picture1.hdc etc.). Hdc's are for visible regions only. That means that you have to resize the picbox
until all controls in the picbox are visible.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.