Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

BitBlt from an image control

Posted on 2000-03-26
6
Medium Priority
?
375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 28

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 28

Accepted Solution

by:
Ark earned 400 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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