Solved

vb6: saving a picture painted with autoredraw=false

Posted on 2009-05-10
7
906 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
 
LVL 13

Expert Comment

by:game-master
ID: 24351087
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

830 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