Solved

vb6: saving a picture painted with autoredraw=false

Posted on 2009-05-10
7
900 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

803 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