|
-
Mar 4th, 2003, 12:23 PM
#1
Thread Starter
Member
picturebox problem [RESOLVED]
I have been developing a program and am now trying to save its contents. What i have is a picturebox with several things inside of it including textboxes, and other pictureboxes. All i want to do is save the main picturebox along with all of the other stuff inside of it to a .bmp or a .jpg. I have tried all the normal things but nothing inside the picture box is saved. Does anyone have any thoughts on that? The file is physically created, however it does not contain the contents of the picturebox, only the border of the picturebox.
This is my current code:
SavePicture frmImage3.Picture1.Image, CommonDialog1.filename
I also tried
SavePicture frmImage3.Picture1.Picture, CommonDialog1.filename
and ive also tried changing the AutoRedraw function. However none of these work properly.. i get the same results each time.
Thanks in advance.
Last edited by ParadoxMember; Mar 5th, 2003 at 12:01 PM.
Sometimes the simplest things are the hardest...
-
Mar 4th, 2003, 01:06 PM
#2
Frenzied Member
Pay attention to comments:
VB Code:
Private Sub Command1_Click()
'-----------------------------------------------------------------------------
'FROM MSDN:
'If a graphic was loaded from a file to the Picture property of an object,
'either atdesign time or atrun time, and it’s a bitmap, icon, metafile,
'or enhanced metafile, it's saved using the same format as the original file.
'If it is a GIF or JPEG file, it is saved as a bitmap file.
'-----------------------------------------------------------------------------
CommonDialog1.Filter = "Pictures (*.bmp;*.ico;*.wmf)|*.bmp;*.ico;*.wmf"
CommonDialog1.ShowSave
SavePicture Picture1.Picture, CommonDialog1.FileName
End Sub
-
Mar 4th, 2003, 01:14 PM
#3
Thread Starter
Member
picturebox...
The file that i opened into the picturebox was a jpg, and it still did not save when i saved it as a bmp.
'FROM MSDN:
'If it is a GIF or JPEG file, it is saved as a bitmap file.
Is it possible to save items that are stored inside a picturebox?
Even my textboxes are not saving!
Thanks for the reply though... I appreciate it.. I'm really throwing my head against a brick wall here!
Sometimes the simplest things are the hardest...
-
Mar 4th, 2003, 01:19 PM
#4
Frenzied Member
Is it possible to save items that are stored inside a picturebox?
I already gave you the answer.
Even my textboxes are not saving!
Not sure I follow you ...
-
Mar 4th, 2003, 01:26 PM
#5
Thread Starter
Member
picturebox
Im sorry if i was confusing... my problem is simply this: nothing i put inside the picturebox saves. I have an option where u can press a button and add textboxes and pictureboxes to the picturebox. But when i click save i get nothing. simply the frame of the original picturebox. Nothing inside of it. No text, no additional images.. i am rather confused as to why.
Sometimes the simplest things are the hardest...
-
Mar 4th, 2003, 03:06 PM
#6
Hyperactive Member
Because when your SavePicture its saving the image held in the PictureBox's picture object. Sounds like your using the PictureBox as a container for other things. Even those things such as your textboxes are contained in there, they havent been added to the picture box's image.
However there are ways of doing it. You could CaptureDC of the picture boxes area and save it to the picturebox.picture object. Then you should be able to save it as a bmp. You cant save as a JPG unless you know the compression for jpg or have a third-party control which has been talked about in these forums.
-
Mar 4th, 2003, 03:31 PM
#7
Hyperactive Member
Try this and set the PictureBox's AutoDraw = True
VB Code:
'______________________________________
'
' Declarations
'______________________________________
Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDCDest As Long, _
ByVal XDest As Long, _
ByVal YDest As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hDCSrc As Long, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
ByVal dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" _
(ByVal hwnd As Long, _
ByVal hdc As Long) As Long
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, _
lpRect As RECT) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'______________________________________
'
' Form Code To Flatten Image and Save
'______________________________________
Private Sub Command1_Click()
Dim Desktop As Long
Dim DesktopDC As Long
'find the position of PictureBox on screen
Dim MainL As RECT
GetWindowRect Picture1.hwnd, MainL
'capture desktop DC
Desktop = GetDesktopWindow
DesktopDC = GetDC(Desktop)
'bitblt into PictureBox
BitBlt Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, DesktopDC, MainL.Left, MainL.Top, vbSrcCopy
'Release the device context
Call ReleaseDC(Desktop, DesktopDC)
'save to bmp
SavePicture Picture1.Image, "C:\ss.bmp"
End Sub
Last edited by Eyes.Only; Mar 4th, 2003 at 06:26 PM.
-
Mar 4th, 2003, 03:50 PM
#8
Thread Starter
Member
cool
I had to change this code:
'Release the device context
Call ReleaseDC(hWndDesk, hDCDesk)
to this:
'Release the device context
Call ReleaseDC(hWnd, hDC)
I am not sure exactly why.. but I did.. anyway.. thank you it worked perfectly...
Sorry to bother.. but one last question... is there anyway i could save it so that it can be edited at a later date..? i cant modify a bmp at a later date.. just a question if its possible.. but thank you for the code... that was a lifesaver..
Sometimes the simplest things are the hardest...
-
Mar 4th, 2003, 04:05 PM
#9
Frenzied Member
Sorry, couldn't get back to you earlier.
I see now where you're heading. No, that's not what savePicture was desined for: primerily saving loaded picture. What you needed was Screen capturing and that code snippet from Eyes.Only should do it. Second part of your question is has nothing to do with saving picture but the content of your Textboxes (or whatever) to say Text file so you can easily open it later and load its data back into a textbox.
-
Mar 4th, 2003, 04:16 PM
#10
Thread Starter
Member
so basically..
So basically its going to be a real pain to get the files so that i can edit them later? bummer
Sometimes the simplest things are the hardest...
-
Mar 4th, 2003, 04:55 PM
#11
Frenzied Member
Nor really. Here is what you need to do:
VB Code:
'To save to a file
Open App.Path & "\tempdata.txt" For Output As #1
Print #1, Text1.Text
Close #1
'To get from a file
Open App.Path & "\tempdata.txt" For Input As #1
Text1.Text = Input(LOF(1), #1)
Close #1
There will be some variations, of course, but it wouldn't be that complex.
-
Mar 4th, 2003, 05:24 PM
#12
Thread Starter
Member
thanks
Thank you so much for the code... I have to get out of the office now but I will try this more tomorrow.. thank you all for all your help!...
Sometimes the simplest things are the hardest...
-
Mar 4th, 2003, 06:28 PM
#13
Hyperactive Member
whoops...my bad. I copied that line from my project and then forgot to change the variable names. I edited that post to reflect the right names now. I would take a look to make sure you get it right cuz you dont want any memory leaks
-
Mar 5th, 2003, 10:21 AM
#14
Thread Starter
Member
not a problem
Thanks for the heads up... i did run through the code quickly and everything else appreaded to be correct, but I will double check that... still learning a lot of this stuff...
As for the saving files I think i must have the syntax wrong... because the file is saving properly (with all of the options I have tried so far), but then i cannot re-load the file.
This is my code to save the file:
Private Sub Command8_Click()
Open App.Path & "\tempdata.txt" For Output As #1
Print #1, Picture5(0).Height
Print #1, Picture5(0).Width
Print #1, Text1.text
Print #1, Text1.Height
Print #1, Text1.Width
Close #1
End Sub
This works, it saves in the textfile perfectly..
However, my code to reopen the file does not work right at all, at the moment i am getting a type mismatch error, but i have gotten many others as well.
Private Sub Command9_Click()
Open App.Path & "\tempdata.txt" For Input As #1
Picture5(0).Height = Input(LOF(1), #1)
Picture5(0).Width = Input(LOF(2), #1)
Text1.text = Input(LOF(3), #1)
Text1.Height = Input(LOF(4), #1)
Text1.Width = Input(LOF(5), #1)
Close #1
End Sub
I assumed the LOF mean "Line of File" which is why it is so numbered, but I may be wrong since ive never done this before ... any thoghts? Thanks
Sometimes the simplest things are the hardest...
-
Mar 5th, 2003, 11:44 AM
#15
Frenzied Member
Re: picturebox problem
To simplify Eyes.Only's code, there is a PrintWindow API Call
VB Code:
Private Declare Function PrintWindow Lib "user32" _
(ByVal hWnd As Long, _
ByVal hdcBlt As Long, _
ByVal nFlags As Long) As Long
Private Sub Command1_Click()
With Picture2
.Height = Picture1.Height
.Width = Picture1.Width
.AutoRedraw = True
End With
Call PrintWindow(Picture1.hWnd, Picture2.hdc, 0)
SavePicture Picture2.Image, App.Path & "\bmpFromPicBox.bmp"
Shell "Mspaint.exe " & App.Path & "\bmpFromPicBox.bmp"
End Sub
Private Sub Form_Load()
Picture2.Visible = False
End Sub
HTH
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Mar 5th, 2003, 12:00 PM
#16
Thread Starter
Member
thanks
Thanks for all the input... i finally found what i was looking for on how to save the files into a textbox so they are editable in another thread... its going to be a lot of code to save everything becuase users can add dynamic content.. but it is doable i am sure about that... so thanks everyone for all your help
Sometimes the simplest things are the hardest...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|