Solved

vb6: saving a picture painted with autoredraw=false

Posted on 2009-05-10
7
914 Views
Last Modified: 2012-05-06
Dear Experts,

I am using picturebox1.paintpicture with autoredraw = false because with large images it takes much too long to complete when autoredraw=true.

With autoredraw=true, I can grab the painted image by using the statement: picturebox1.picture=picturebox1.image but this does not work when autoredraw=false. Also tried changing autoredraw to true after painting, but this did not work either.

How can I grab the image painted into the picturebox when it was painted with autoredraw=false?

Thanks!
0
Comment
Question by:ttobin333
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 13

Expert Comment

by:game-master
ID: 24350798


good morning!

where you going to place the grab picture by d way?
0
 

Author Comment

by:ttobin333
ID: 24350950
Hi game-master! Into another picture box.
0
 
LVL 13

Expert Comment

by:game-master
ID: 24351087
0
Independent Software Vendors: 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!

 

Author Comment

by:ttobin333
ID: 24351118
Those won't work...I need to paint the picture with autoredraw  = false but be able to save it afterward.
0
 
LVL 4

Expert Comment

by:learning_t0_pr0gram
ID: 24352167
You could use BitBlt to accomplish this.

If you want to copy what's drawn in Picture1 into Picture2, you would do it like:

BitBlt Picture2.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hDC, 0, 0, vbSrcCopy

The declaration:

Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (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
0
 
LVL 4

Accepted Solution

by:
learning_t0_pr0gram earned 500 total points
ID: 24352291
I realized that this still wouldn't allow you to save.  this method should allow you to though.  this code will copy what's in Picture1 into memory, and store it in a Picture variable rather than a PictureBox itself.  you can then set it to show in the new picturebox (if you wish), or you can save it to file directly from memory.  either way would work fine.

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 Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Private Declare Function OleCreatePictureIndirect Lib "olepro32" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long


Private Type GUID
   Data1 As Long
   Data2 As Integer
   Data3 As Integer
   Data4(7) As Byte
End Type

Private Type PicBmp
   Size As Long
   Type As Long
   hBmp As Long
   hPal As Long
   Reserved As Long
End Type

Private Sub Command1_Click()

    Dim BMP As Long, BMPPrev As Long, nDC As Long, G As GUID, Pic As PicBmp, IPic As IPictureDisp, P As Picture

    nDC = CreateCompatibleDC(Picture1.hdc)
    BMP = CreateCompatibleBitmap(Picture1.hdc, Picture1.ScaleWidth, Picture1.ScaleHeight)
   
    BMPPrev = SelectObject(nDC, BMP)
   
    BitBlt nDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
   
    BMP = SelectObject(nDC, BMPPrev)
   
    DeleteDC nDC
    ReleaseDC Picture1.hWnd, Picture1.hdc
   
    With G
      .Data1 = &H20400
      .Data4(0) = &HC0
      .Data4(7) = &H46
    End With

    With Pic
        .Size = Len(Pic)
        .Type = vbPicTypeBitmap
        .hBmp = BMP
        .hPal = 0&
    End With
    Call OleCreatePictureIndirect(Pic, G, 1, IPic)
   
    Set P = IPic

    Picture2.Picture = P  'show in new picturebox
    SavePicture P, App.Path & "\my.bmp" 'save directly from memory
End Sub
0
 

Author Comment

by:ttobin333
ID: 24381303
Thanks, learning_t0_pr0gram...I'm trying to adapt this to work in my program.

I may have a couple questions as I do this...thanks for your patience!
0

Featured Post

Industry Leaders: 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 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