Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb6: saving a picture painted with autoredraw=false

Posted on 2009-05-10
7
Medium Priority
?
957 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses

916 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