\r\n\r\n
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > saving picturebox bitmap


\r\n \r\n
 
 
Thread Tools Display Modes

\r\n\r\n\r\n
How can i save the bitmaps created in picturebox?
\n
\nripley
\r\n \r\n\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; pd[5155] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n \r\n \r\n\r\n
\r\n
\r\n  \r\n #2  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 09-04-2000, 05:02 AM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Phil\r\n \r\n
\r\n\r\n
Guest
\r\n \r\n \r\n\r\n
 \r\n\r\n
\r\n \r\n \r\n \r\n
\r\n Posts: n/a\r\n
\r\n \r\n \r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n \r\n
\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n
\r\n Default\r\n Re: saving picturebox bitmap\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n\r\n \r\n\r\n\r\n
Hi,
\nTo save the picture property of a picturebox you can simply use the SavePicture statement. To save an image created in a picturebox is more complex, I managed to addapt some code found in the MSDN article Q161299 to do the job. You can find this at:
\n
\nhttp://support.microsoft.com/support...S&SD=msdn&FR=0
\n
\nThere may be an easier way to do this but I couldn\'t find it so for what it\'s worth here is the code I use (without any error handling,so you may wish to look at that).
\n
\nTo test this create a project with a default form containing a picturebox Picture1 with SCALEMODE set to PIXELS and a command button command1. Paste this code, create some graphics at design time and hit the command1 hopefully a bitmap "test.bmp" will be created in the "C:Temp" directory.
\n
\n
\nOption Explicit
\n
\n Private Const SRCCOPY = &HCC0020 \' (DWORD) dest = source
\n
\n Private Type GUID
\n Data1 As Long
\n Data2 As Integer
\n Data3 As Integer
\n Data4(7) As Byte
\n End Type
\n
\n Private Declare Function CreateCompatibleDC Lib "gdi32" ( _
\n ByVal hdc As Long) As Long
\n Private Declare Function CreateCompatibleBitmap Lib "gdi32" ( _
\n ByVal hdc As Long, ByVal nWidth As Long, _
\n ByVal nHeight As Long) As Long
\n Private Declare Function SelectObject Lib "gdi32" ( _
\n ByVal hdc As Long, ByVal hObject As Long) As Long
\n Private Declare Function BitBlt Lib "gdi32" ( _
\n ByVal hDCDest As Long, ByVal XDest As Long, _
\n ByVal YDest As Long, ByVal nWidth As Long, _
\n ByVal nHeight As Long, ByVal hDCSrc As Long, _
\n ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) _
\n As Long
\n Private Declare Function DeleteDC Lib "gdi32" ( _
\n ByVal hdc As Long) As Long
\n Private Declare Function ReleaseDC Lib "user32" ( _
\n ByVal hwnd As Long, ByVal hdc As Long) As Long
\n Private Declare Function GetWindowDC Lib "user32" ( _
\n ByVal hwnd As Long) As Long
\n
\n Private Type picBmp
\n Size As Long
\n Type As Long
\n hBmp As Long
\n hPal As Long
\n Reserved As Long
\n End Type
\n
\n Private Declare Function OleCreatePictureIndirect _
\n Lib "olepro32.dll" (PicDesc As picBmp, RefIID As GUID, _
\n ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
\n
\n Private Declare Function StretchBlt Lib "gdi32" _
\n (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _
\n ByVal nWidth As Long, ByVal nHeight As Long, _
\n ByVal hSrcDC As Long, ByVal xSrc As Long, _
\n ByVal ySrc As Long, ByVal nSrcWidth As Long, _
\n ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
\n
\nPublic Function CreateBitmapPicture(ByVal hBmp As Long) As Picture
\n
\n Dim R As Long
\n Dim Pic As picBmp
\n\' IPicture requires a reference to "Standard OLE Types."
\n Dim IPic As IPicture
\n Dim IID_IDispatch As GUID
\n
\n\' Fill in with IDispatch Interface ID.
\n
\n With IID_IDispatch
\n .Data1 = &H20400
\n .Data4(0) = &HC0
\n .Data4(7) = &H46
\n End With
\n
\n\' Fill Pic with necessary parts.
\n With Pic
\n .Size = Len(Pic) \' Length of structure.
\n .Type = vbPicTypeBitmap \' Type of Picture (bitmap).
\n .hBmp = hBmp \' Handle to bitmap.
\n End With
\n
\n\' Create Picture object.
\n R = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
\n
\n\' Return the new Picture object.
\n Set CreateBitmapPicture = IPic
\n
\nEnd Function
\n
\nPublic Function exportBmp(PBox As PictureBox) As Picture
\n\'
\n Dim hDCMemory As Long
\n Dim hBmp As Long
\n Dim hBmpPrev As Long
\n Dim R As Long
\n Dim hDCSrc As Long
\n Dim hPal As Long
\n Dim hPalPrev As Long
\n Dim RasterCapsScrn As Long
\n Dim HasPaletteScrn As Long
\n Dim PaletteSizeScrn As Long
\n Dim WidthPix As Single
\n Dim HeightPix As Single
\n
\n WidthPix = PBox.ScaleWidth
\n HeightPix = PBox.ScaleHeight
\n
\n hDCSrc = GetWindowDC(PBox.hwnd) \' Get device context for pbox.
\n
\n\' Create a memory device context for the copy process.
\n hDCMemory = CreateCompatibleDC(hDCSrc)
\n\' Create a bitmap and place it in the memory DC.
\n hBmp = CreateCompatibleBitmap(hDCSrc, WidthPix, HeightPix)
\n hBmpPrev = SelectObject(hDCMemory, hBmp)
\n
\n\' Copy the on-screen image into the memory DC.
\n R = BitBlt(hDCMemory, 0, 0, WidthPix, HeightPix, hDCSrc, _
\n 0, 0, vbSrcCopy)
\n
\n\' Remove the new copy of the on-screen image.
\n hBmp = SelectObject(hDCMemory, hBmpPrev)
\n
\n\' Release the device context resources back to the system.
\n R = DeleteDC(hDCMemory)
\n R = ReleaseDC(PBox.hwnd, hDCSrc)
\n
\n\' Call CreateBitmapPicture to create a picture object from the
\n\' bitmap. Then return the resulting picture object.
\n
\n Set exportBmp = CreateBitmapPicture(hBmp)
\n
\nEnd Function
\nPrivate Sub Command1_Click()
\n\'
\n\'save as bitmap option prompts for file name
\n
\n Dim FileSpec As String
\n
\n FileSpec = "c: empTest.bmp"
\n SavePicture exportBmp(Picture1), FileSpec
\n
\nEnd Sub
\n
\nGood Luck Phil
\n
\n
\r\n \r\n\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\n \r\n
\r\n
\r\n
\r\n\r\n\r\n\r\n'; pd[5156] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n \r\n \r\n\r\n
\r\n
\r\n  \r\n #3  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 09-04-2000, 12:25 PM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n amram71\r\n \r\n
\r\n\r\n
Guest
\r\n \r\n \r\n\r\n
 \r\n\r\n
\r\n \r\n \r\n \r\n
\r\n Posts: n/a\r\n
\r\n \r\n \r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n \r\n
\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n
\r\n Default\r\n Re: saving picturebox bitmap\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n\r\n \r\n\r\n\r\n
Sorry Phil, But i\'m pretty positive you can save images Created in a PicBox using absoluely no API, but, like u mentioned, the SavePicture statement.
\nThere are 2 properties of a PBOx that you can use.
\nPicture Property, to get the Picture in the Box.
\nImage Property, to get any thing in the box.
\nSo yo ucould do SavePicture Picture1.Image
\n
\nCorrect me if I\'m Wrong
\n
\n
\r\n \r\n\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\n \r\n
\r\n
\r\n
\r\n\r\n\r\n\r\n'; pd[5157] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n\r\n\r\n \r\n \r\n\r\n
\r\n
\r\n  \r\n #4  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 09-05-2000, 04:15 AM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Phil\r\n \r\n
\r\n\r\n
Guest
\r\n \r\n \r\n\r\n
 \r\n\r\n
\r\n \r\n \r\n \r\n
\r\n Posts: n/a\r\n
\r\n \r\n \r\n \r\n \r\n
\r\n
\r\n\r\n
\r\n \r\n
\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n
\r\n Default\r\n Re: saving picturebox bitmap\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n\r\n \r\n\r\n\r\n
Hi,
\n
\nThanks, you live and learn!
\nThe mistake comes from the fact that in my original code I had to save graphic "controls" such as line and shape and other pictureboxes within the container picturebox, created at design time. The only way I could find to do this was with the above.
\nWe sometimes spend so long looking for complex solutions we overlook the straight forward, thanks for pointing it out.
\n
\nPhil
\n
\n
\r\n \r\n\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\n \r\n
\r\n
\r\n
\r\n\r\n\r\n\r\n'; // next/previous post info pn[5154] = "5157,5155"; pn[0] = ",5154"; pn[5155] = "5154,5156"; pn[5156] = "5155,5157"; pn[5157] = "5156,5154"; // cached usernames pu[0] = guestphrase; // -->
Prev Previous Post   Next Post Next
  #1  
Old 09-03-2000, 09:41 PM
rodf
Guest
 
Posts: n/a
Default saving picturebox bitmap


How can i save the bitmaps created in picturebox?

ripley
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->