473,714 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save Picturebox

Dear all..
I have a picturebox filled on a form. The picturebox has some
graphics displayed on it.I was trying to save the picturebox, but
continuesly failed to do so. I am clueless of why it is happening. I
tried to save the image of the form & also the picturebox, but always,
i see a blank file saved. Is there a way to save whatever is displayed
on the picturebox, to a file??
Thanks for any suggestions and help.

Regards,
Pavan
Jul 17 '05 #1
8 31521
On 17 Jun 2004 21:45:25 -0700, pa*********@yah oo.com (Pavan Arise)
wrote:
Dear all..
I have a picturebox filled on a form. The picturebox has some
graphics displayed on it.I was trying to save the picturebox, but
continuesly failed to do so. I am clueless of why it is happening. I
tried to save the image of the form & also the picturebox, but always,
i see a blank file saved. Is there a way to save whatever is displayed
on the picturebox, to a file??
Thanks for any suggestions and help.


Set the Picturebox's AutoRedraw = True

SavePicture Picture1.Image, FileName
Jul 17 '05 #2
I am still not able to save the picturebox/ I am hereby attaching the
code here.
This is the code which I have in the sub:
=============== ==
In Declarations Section
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As
Long, ByVal hWndNewParent As Long) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long,
ByVal X As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight
As Long, ByVal bRepaint As Long) As Long

' Following code in Sub/
------
Dim Dum As New FrmRotSyncPlt

Load FrmRotSyncPlt ' FrmRotSyncPlt is the form where the whole
graphics is printed & also has the picturebox

Call SetParent(FrmRo tSyncPlt.hwnd, Dum.hwnd)

Call MoveWindow(FrmR otSyncPlt.hwnd, 0, 0, 800, 600, True)
' I alreday have the SetParent & MoveWindow declared in the
declarations section (As previously given by Seth)
Dum.Show
SavePicture Dum.Image, "c:/trial.bmp"
Debug.Print "done"

End sub
============
I also tried it with copying the whole form into a picturebox on Dum
, as suggested by Seth above, but without any sucess. The saved
trial.Bmp is always blank. Thanks for any suggestions & help.
Jul 17 '05 #3
wait a second ...

From what you post ... on one hand you Dim a variable 'Dum' as a form type,
then proceed to not properly initialize it to a form. You then do APIs to
FrmRotSyncPlt, setting parent to the non-existent form, then attempt to save
a picture from this same non-existent (non-visible, non-referenced) form
using the image property of a picturebox.

What makes you think that following a SetParent call, that a picturebox
contained on FrmRotSyncPlt will somehow become the picturebox on the other
form?

1) saving the Image property of a form only saves -- quite literally -- an
image the form itself (no contained controls). If you were to draw onto the
form canvas you would 'see' the saved form picture, but any controls on the
form would not be visible.

2) if you have a valid picture in a picturebox, execute:

picture1.pictur e = picture1.image
savepicture picture1.pictur e, "c:\temp.bm p"

Once you 'setparent' a form all bets are off as to the success of any given
activity. Using SetParent to reparent one form to another is at best a hack,
and unsupported.

Better explain things more clearly.

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Pavan Arise" <pa*********@ya hoo.com> wrote in message
news:eb******** *************** ***@posting.goo gle.com...
: I am still not able to save the picturebox/ I am hereby attaching the
: code here.
: This is the code which I have in the sub:
: =============== ==
: In Declarations Section
: Private Declare Function SetParent Lib "user32" (ByVal hWndChild As
: Long, ByVal hWndNewParent As Long) As Long
: Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long,
: ByVal X As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight
: As Long, ByVal bRepaint As Long) As Long
:
: ' Following code in Sub/
: ------
: Dim Dum As New FrmRotSyncPlt
:
: Load FrmRotSyncPlt ' FrmRotSyncPlt is the form where the whole
: graphics is printed & also has the picturebox
:
: Call SetParent(FrmRo tSyncPlt.hwnd, Dum.hwnd)
:
: Call MoveWindow(FrmR otSyncPlt.hwnd, 0, 0, 800, 600, True)
: ' I alreday have the SetParent & MoveWindow declared in the
: declarations section (As previously given by Seth)
: Dum.Show
: SavePicture Dum.Image, "c:/trial.bmp"
: Debug.Print "done"
:
: End sub
: ============
: I also tried it with copying the whole form into a picturebox on Dum
: , as suggested by Seth above, but without any sucess. The saved
: trial.Bmp is always blank. Thanks for any suggestions & help.

Jul 17 '05 #4
Dear Randy Birch..thanks for the suggestion, I think I have messed up
the code completely. What I was trying to do was to save a form(it has
some plot drawn on it) along with a picturebox on it. As you said,
when I tried with Picturesave, I am not able to save the controls. My
try with the setparent is not yeilding any results either. I am now
wondering(and trying) if Bitblt would serve the purpose of saving the
form along with its control content.Can you please help me.
Thanks in advance for any suggestions/
Jul 17 '05 #5
If you use this ... http://vbnet.mvps.org/code/bitmap/printscreenole.htm ...
and in the GetOLEScreenSna pshot routine substitute:

'CaptureWindow
WidthSrc = me.Width \ Screen.TwipsPer PixelX
HeightSrc = me.Height \ Screen.TwipsPer PixelY

'Get a handle to the desktop window and get the proper device context
hWndSrc = Me.hwnd

.... for ...

'CaptureWindow
WidthSrc = Screen.Width \ Screen.TwipsPer PixelX
HeightSrc = Screen.Height \ Screen.TwipsPer PixelY

'Get a handle to the desktop window and get the proper device context
hWndSrc = GetDesktopWindo w()
.... you'll get a pix of the form in Picture1 - including its controls and
control contents - which you can then save using the code I provided
earlier:

picture1.pictur e = picture1.image
savepicture picture1.pictur e, "c:\temp.bm p"

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Pavan Arise" <pa*********@ya hoo.com> wrote in message
news:eb******** *************** ***@posting.goo gle.com...
: Dear Randy Birch..thanks for the suggestion, I think I have messed up
: the code completely. What I was trying to do was to save a form(it has
: some plot drawn on it) along with a picturebox on it. As you said,
: when I tried with Picturesave, I am not able to save the controls. My
: try with the setparent is not yeilding any results either. I am now
: wondering(and trying) if Bitblt would serve the purpose of saving the
: form along with its control content.Can you please help me.
: Thanks in advance for any suggestions/

Jul 17 '05 #6
Thank you Randy Birch for the invaluable piece of code. I have the
program working perfectly as I wanted. But there is a small problem
here. I was trying to save just the form content only. By the way it
is now, the title bar (Wher the caption is written) is also getting
saved. I tried to change the form borderstyle setting to 0 (None) &
refreshing the form before calling the GetOLEScreenSna pshot sub, but
for some reason, the form border isn't changing and the form along
with the titlebar is getting saved. There were some other buttons on
the form which were not saved when I had them as visible =false during
runtime. Is it that the borderstyle doesn't change during runtime, or
are there any other changes to be made for having the titlebar not to
be saved with the form. Thank you again and any suggestions are
appreciated.
Jul 17 '05 #7
Try this slightly tweaked routine. The values set for the voffset and
hoffset values work on my system using small fonts. You may need to tweak
the values to correctly clip for large font systems. Basically this uses the
form's scaleheight and scalewidth rather than its width/height to size the
bitmap, then offsets the bitblt'ed image to subtract the borders and
titlebar.

Private Function GetOLEScreenSna pshot() As Picture

Dim hWndSrc As Long
Dim hDCSrc As Long
Dim hDCMemory As Long
Dim hBmp As Long
Dim hBmpPrev As Long
Dim WidthSrc As Long
Dim HeightSrc As Long
Dim Pic As PicBmp
Dim IPic As IPicture
Dim IID_IDispatch As GUID

Dim vOffset As Long
Dim hOffset As Long

'CaptureWindow
WidthSrc = Me.ScaleWidth \ Screen.TwipsPer PixelX
HeightSrc = Me.ScaleHeight \ Screen.TwipsPer PixelY

vOffset = ((Me.Width - Me.ScaleWidth) / 1.75) \ Screen.TwipsPer PixelX
hOffset = ((Me.Height - Me.ScaleHeight) / 1.15) \ Screen.TwipsPer PixelY

'Get a handle to the desktop window and get the proper device context
hWndSrc = Me.hWnd
hDCSrc = GetWindowDC(hWn dSrc)

'Create a memory device context for the copy process
hDCMemory = CreateCompatibl eDC(hDCSrc)

'Create a bitmap and place it in the memory DC
hBmp = CreateCompatibl eBitmap(hDCSrc, WidthSrc, HeightSrc)
hBmpPrev = SelectObject(hD CMemory, hBmp)

Print vOffset, hOffset

'Copy the on-screen image into the memory DC
Call BitBlt(hDCMemor y, 0, 0, WidthSrc, HeightSrc, _
hDCSrc, vOffset, hOffset, vbSrcCopy)

'Remove the new copy of the the on-screen image
hBmp = SelectObject(hD CMemory, hBmpPrev)

'Release the device context resources back to the system
Call DeleteDC(hDCMem ory)
Call ReleaseDC(hWndS rc, hDCSrc)

'Fill in OLE IDispatch Interface ID
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With

'Fill Pic with necessary parts
With Pic
.Size = Len(Pic) 'Length of structure
.Type = vbPicTypeBitmap 'Type of Picture (bitmap)
.hBmp = hBmp 'Handle to bitmap
.hPal = 0& 'Handle to palette (may be null)
End With

'Create OLE Picture object
Call OleCreatePictur eIndirect(Pic, IID_IDispatch, 1, IPic)

'Return the new Picture object
Set GetOLEScreenSna pshot = IPic

End Function

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Pavan Arise" <pa*********@ya hoo.com> wrote in message
news:eb******** *************** **@posting.goog le.com...
: Thank you Randy Birch for the invaluable piece of code. I have the
: program working perfectly as I wanted. But there is a small problem
: here. I was trying to save just the form content only. By the way it
: is now, the title bar (Wher the caption is written) is also getting
: saved. I tried to change the form borderstyle setting to 0 (None) &
: refreshing the form before calling the GetOLEScreenSna pshot sub, but
: for some reason, the form border isn't changing and the form along
: with the titlebar is getting saved. There were some other buttons on
: the form which were not saved when I had them as visible =false during
: runtime. Is it that the borderstyle doesn't change during runtime, or
: are there any other changes to be made for having the titlebar not to
: be saved with the form. Thank you again and any suggestions are
: appreciated.

Jul 17 '05 #8
Dear Randy Birch,
The changed routine that you have provided has solved my purpose
exactly to the core. I am very much thankful to you for helping me
out. I was trying to crack it for more than a week continuously & you
have made it for me exactly as I wanted. I thank you very much again/

Regards,
Pavan.
Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
16406
by: Michael Lehar | last post by:
Hallo I have a pictureBox with a picture loaded from file, then I draw some lines on the picture, and then I want to save the new picture. Befor I can draw lines I have to create a Graphics object, with g = pictureBox.CreateGraphic, and draw lines g.drawLines(....) But when saving the picture, the new picture have no lines, it is only a copy.
7
25492
by: user | last post by:
Hello I tried: pictureBox1.Image.Save("file.sav"); compiled, but when i run i receive errors: Additional information: Object reference not set to an instance of an object. Why ?
3
11645
by: Alexli | last post by:
I got the error ================= An unhandled exception of typ 'System.Runtime.InteropServices.ExternalException' occurred i system.drawing.dl Additional information: A generic error occurred in GDI+ ================= the code like this
12
57294
by: yaya via DotNetMonster.com | last post by:
Hi, I have a picture box with circles and rectangles, and I wana save all the images into a jpg file, i tried pictureBox1.Image.Save(@"c:\1.jpg"); but I got and error "System.NullReferenceException: Object reference not set to an instance of an object." Can anyone help? Thanks... --
0
3882
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for your help, Here is the code.
0
4875
by: ramya naidu | last post by:
Hai friends i have cod eto draw and save picture in textbox and i need to save that image so iam using this code when i save the image and reopen it is not saving plz any one help me i have written this code under save in menustrip and i run code sfd.InitialDirectory = System.Windows.Forms.Application.StartupPath; sfd.AddExtension = true; sfd.Title = "Save an image file"; sfd.Filter = "JPEG Files...
0
1421
Computer Guru
by: Computer Guru | last post by:
On Error Resume Next Dim SaveFileDialog As New SaveFileDialog SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments SaveFileDialog.Filter = "Icon (*.ico)|*.ico" If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then Dim sFilename As String = SaveFileDialog.FileName
10
7419
by: eddie tan | last post by:
Hi, I have a picturebox with graphics drawn from different objects. In one object I used Pen P1; P1 = new Pen(Color.Blue, 3); Graphics g = null; g = Graphics.FromImage(image.Image); g.DrawPath(P1, Wirepath);
0
8707
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9015
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5947
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2110
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.