Solved

BitBlt from an image control

Posted on 2000-03-26
6
298 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

707 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

11 Experts available now in Live!

Get 1:1 Help Now