[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-04-21
5
Medium Priority
?
2,132 Views
Last Modified: 2013-12-25
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!
0
Comment
Question by:nashuald
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:vb_elmar
ID: 16509791
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
 

Author Comment

by:nashuald
ID: 16510271
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
 
LVL 17

Accepted Solution

by:
vb_elmar earned 2000 total points
ID: 16510883
'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
 

Author Comment

by:nashuald
ID: 16511891
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
 
LVL 17

Expert Comment

by:vb_elmar
ID: 16512163
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question