Solved

BitBlt from an image control

Posted on 2000-03-26
6
311 Views
Last Modified: 2008-02-26
I have used picture boxes and the API function BitBlt without any problem. The picture box has a hDC handle for the API function.

I am now using an image control and need to BitBlt the image to a form and/or printer hDc.  I need the image control for it's stetch attribute,which a picture box does not have.  Anyone know of a way to get the hDc for an image control, or another method to move this image directory to a form or printer hDc?

The only thing I thought of, is, when I need to put the image, is move the image control picture to a hidden picture box, and then use StretchBlt to put the image on the form, from the piture box.  A bit of coding and processor cycles.  Any other ideas?
0
Comment
Question by:rmichels
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2659586
Put an Image Control *inside* a PictureBox Control, then you can use the hDC of the PictureBox:

Private Sub Command1_Click()
    With Picture1
    .BorderStyle = 0 'none
    Image1.Stretch = True
    Image1.Top = 0
    Image1.Left = 0
    Set Image1.Picture = LoadPicture("c:\test.bmp")
    'Set Picture1 same size as Image1
    .Width = Image1.Width
    .Height = Image1.Height
    .Refresh
   
    'Optional - Now use bitblt
    Call BitBlt(Me.hDC, 0, 0, .Width / 15, .Height / 15, .hDC, 0, 0, vbSrcCopy)
   
    End With
End Sub
0
 
LVL 27

Expert Comment

by:Ark
ID: 2659603
Hi
Why you need only BitBlt function? You can use Render method for stdPicture object:

Private Sub Command_Click()
  Dim stdPic As StdPicture, outhDc As Long
  Set stdPic = Image1.Picture
  outhDc = Me.hdc
' or outhDc = Printer.hdc
  stdPic.Render outhDc, 100, 100, 200, 200, 0, 0, stdPic.Width, stdPic.Height, vbNull
End Sub
0
 
LVL 27

Accepted Solution

by:
Ark earned 100 total points
ID: 2659697
BTW, if you choose Image control only for stretching, you can simply do this with Picturebox:

Private Sub Command1_Click()
  StretchPB Picture1
End Sub

Private Sub StretchPB(pic As PictureBox)
  Dim stdPic As StdPicture
  Set stdPic = pic.Picture
  pic.AutoRedraw = True
  pic.PaintPicture stdPic, 0, 0, pic.Width, pic.Height
  pic.Picture = pic.Image
' If you need
'  pic.AutoRedraw = False
End Sub
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:Ark
ID: 2659710
Hi
About using Render instead of BitBlt. Sorry, one bug - stdPicture has reverse height counting - from bottom to up, so you get reverse picture. Change this string:
  stdPic.Render outhDc, 100, 100, 200, 200, 0, 0, stdPic.Width, stdPic.Height, vbNull

to

  stdPic.Render outhDc, 100, 100, 200, 200, 0, stdPicture.Height, stdPic.Width, -stdPic.Height, vbNull

You can also flip pictures with render method

Cheers
0
 
LVL 3

Author Comment

by:rmichels
ID: 2660734
hmmm, good comments.  I'll try these tonight and see which one works best.

In the mean time I did try my solution above, by setting a picturebox = to my image control, and then using bitblt into the destinati on.  One problem I have is that the image control seems to have a better shrink algorithm than BitBlt.  BitBlt leaves a mess on the image when I shrink it.
0
 
LVL 3

Author Comment

by:rmichels
ID: 2664145
Thanks, the code to do the stretching worked out good, as i really would rather use a picture box.  It has a get focus event that was missing in the image control, which made my life even easier.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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

912 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

22 Experts available now in Live!

Get 1:1 Help Now