Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save picturebox with 2 pictureboxes inside 1

Status
Not open for further replies.

waytech2003

Programmer
Jul 14, 2003
316
US
I want to SavePicture on a Pic0 that contains two other PictureBoxes, called Pic1 and Pic2

------ Pic0 -------
| | |
| {Pic1} | {Pic2} |
| | |
-------------------

When I SavePicture Pic0, "text.bmp"
I get an error 380 "invalid property value"


If I try this,
Pic0.Picture = Pic0.Image
SavePicture Pic0, "test.bmp"

I do not get the error, but I just get an empty image of Pic0 as my bmp.

I have searched the forum but can not find any ideas why this does not work. I thought that SavePicture would save a snapshot of a PictureBox
 
I should also mention that Pic0 may be larger then the screen in the final version of this program. But as of right now it is not.
 
See thread222-1157687 for capturing image of controls.
 

How are the 2 pics combined in one pic box?

Is your combined bitmap really a single bitmap visible by MsPaint?

Maybe enter the Path name for the file? (eg.c:\Pictures\text.bmp)

Maybe if you send the pic to the clipboard then put it into a picturebox as one pic then save it? :-

This saves one freeze frame from a moving webcam that has been put onto the clipboard by an API call-
Clipboard.Setdata "Camera.bmp",vbCFBitmap
Pic0.Picture=Clipboard.Getdata
SavePicture.Pic0, "FreezeFrame.bmp
 
Why don't you place both images into one picture box and save the image of that? or is there a reason why you need to use Picture1 as a container for the other 2 picture boxes?

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Will look into thread that tedsmith pointed out.

Error7, yes I need 2 picture boxes. 1 contains Text that I printed to pic1, the second contains a bmp picture which I loaded into pic2. I placed them both in pic0 in hopes that I could just save that as one big bmp.
 
Well this should work:
'Asuming that your form has 3 PictureBoxes on it
'Assuming that Picture2 already has your image in it
'Assuming that Picture3 has your text in it

Private Sub Command1_Click()
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True
Picture3.AutoRedraw = True

Picture2.Picture = Picture2.Image

Picture1.PaintPicture Picture3.Picture, 0, 0, Picture3.ScaleWidth, Picture3.ScaleHeight
Picture1.PaintPicture Picture2.Picture, Picture3.ScaleWidth, 0, Picture3.ScaleWidth, Picture3.ScaleHeight

SavePicture Picture1.Image, "C:\Test.bmp"
End Sub

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Sorry waytech, the line:

Picture1.PaintPicture Picture2.Picture, Picture3.ScaleWidth, 0, Picture3.ScaleWidth, Picture3.ScaleHeight

Should read:
Picture1.PaintPicture Picture2.Picture, Picture3.ScaleWidth, 0, Picture2.ScaleWidth, Picture2.ScaleHeight

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Interesting stuff Error7
Could this be used to save a picture with a title over it that is typed into a textbox or label?
I have the need to be able to quickly type a message over a pic then send it to another computer as an image, not a file.
And to have a little message in the corner to say where the pic was coming from.
 
No unfortunately not Ted, but you can enter text directly into a picture box and save that using the same method:

Picture2.Print "Add text directly into PictureBox"

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Ted, this is more specific for what you are trying to do:

Private Sub Command1_Click()
Picture1.AutoRedraw = True
Picture2.AutoRedraw = True

'Load image into PictureBox
Picture2.Picture = LoadPicture("C:\MyPic.jpg")

'Move cursor to desired position for text placement
Picture2.CurrentX = 1500
Picture2.CurrentY = 2000

'Add text at desired location
Picture2.Print "TEST"
Picture2.Picture = Picture2.Image

Picture1.PaintPicture Picture2.Picture, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight

SavePicture Picture1.Image, "C:\Test.bmp"
End Sub

[gray]Experience is something you don't get until just after you need it.[/gray]
 
and of course you can set the font size, colour etc with:

Picture2.FontSize = 28
Picture2.FontBold = True
Picture2.ForeColor = vbBlue

[gray]Experience is something you don't get until just after you need it.[/gray]
 
I wish you could edit posts in this forum.

Ted, if you are only handling one image then you can do all this with only one picture box:

Private Sub Command1_Click()
Picture1.AutoRedraw = True

'Load image into PictureBox
Picture1.Picture = LoadPicture("C:\MyPic.jpg")

'Move cursor to desired position for text placement
Picture1.CurrentX = 1500
Picture1.CurrentY = 2000

'Add text at desired location
Picture1.FontSize = 28
Picture1.FontBold = True
Picture1.ForeColor = vbBlue
Picture1.Print "TEST"
Picture1.Picture = Picture1.Image

SavePicture Picture1.Image, "C:\Test.bmp"
End Sub

Alan

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Error7

Below is what I have in my code. Both PaintPicture lines give an error of "Error 481 invalid picture".

I assume that in your example, I am not to have my pictures 1 and 2 contained inside picture 3 as my original layout was. I now have 3 individual pictureboxes 1,2, and 3. Also I believe I need to save Picture3 in last line, not Picture1.

'Assuming that your form has 3 PictureBoxes on it
'Assuming that Picture1 has your text in it
'Assuming that Picture2 already has your image in it

Picture1.AutoRedraw = True 'Printed Text
Picture2.AutoRedraw = True 'BMP Picture
Picture3.AutoRedraw = True 'Final Picture to be saved

Picture2.Picture = Picture2.Image

'Paint Text Pic into final #3
Picture1.PaintPicture Picture3.Picture, 0, 0, Picture3.ScaleWidth, Picture3.ScaleHeight

'Paint BMP Pic into final #3
Picture2.PaintPicture Picture2.Picture, Picture3.ScaleWidth, 0, Picture2.ScaleWidth, Picture2.ScaleHeight

'Save final #3
'SavePicture Picture1.Image, "C:\Test.bmp" 'your code
SavePicture Picture3.Image, "Test.bmp"
 
Got it working [2thumbsup]

'Asuming that your form has 3 PictureBoxes on it
'Assuming that Picture1 has your text in it
'Assuming that Picture2 already has your image in it

Picture1.AutoRedraw = True 'Printed Text
Picture2.AutoRedraw = True 'BMP Picture
Picture3.AutoRedraw = True 'Final Picture to be saved

Picture1.Picture = Picture1.Image
Picture2.Picture = Picture2.Image

'Save Text Pic to final #3
Picture3.PaintPicture Picture1.Picture, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight

'Save BMP to final #3
Picture3.PaintPicture Picture2.Picture, Picture1.ScaleWidth, 0, Picture2.ScaleWidth, Picture2.ScaleHeight

'Save Final #3 as New BMP
SavePicture Picture3.Image, "Room.bmp"
 
Gave Error7 a star for his help.

I would give a second star [thumbsup] to for the code on placing Text on a picture, but forum will not allow this.

Thank all
 
Sorry I wasn't around when you posted your "Error 481 invalid picture" problem

I wasn't ignoring you, I was out visiting Grandkids.

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top