Solved

BitBlt from an image control

Posted on 2000-03-26
6
336 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 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
Technology Partners: 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

733 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