Solved

vb6: saving a picture painted with autoredraw=false

Posted on 2009-05-10
7
877 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now