Solved

BitBlt from an image control

Posted on 2000-03-26
6
319 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2003, my txt file export is running backwards 4 52
Windows 10 start screen issues 9 55
VB6 Compile Compatibility Issue 4 102
Advice in Xamarin 21 79
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…
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…
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…
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…

773 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