2 Replies - 10107 Views - Last Post: 17 June 2010 - 11:58 PM Rate Topic: -----

#1 RMB1791  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-June 10

VB6 Picture Box, picture width and Height

Posted 14 June 2010 - 11:02 PM

Gentlemen, I am stuck.. and so over my head.

My project is to make a Picture Box ActiveX Control .ocx that I may use in VBA MS Access.
Because I need the hDC for BitBlt to use as the destination.hDC. All is well. I made the control
and implemented it in Access. And it works.

Problem: The image that I'm capturing is smaller that the control and smaller than I want to
view it. So... I am trying to add a stretch function to my control using two pictureBoxes.
I will capture to box1 and bitblt to box2 and StretchBlt back to box1. In my direct need and
use I know the pixel size that I captured and StretchBlt it back to box (in VB6 test). I can
ONLY do this because I hard coded the Width and Height in the capture. I know the size.

I can not find a way to measure the Width & Height of the captured pic sitting in box2 as the
source for StretchBlt's to return it to box1.

Question: How to get the W/Height of the Bitmap sitting in a PitureBox in pixels?

The code attached is a simple test model. 2 PicBoxes the capture and StretchBlt
I need to replace the SourceW and SourceH in the StretchBlt with a dynamic answer.
Measuring the size of the source bitmap.

Ive tried many hopeful things... Picture2.Image.Width ect all I get is the size of the
control not the size of the smaller picture inside the control

Again.. the code below runs fine... but, what if someone does a LoadPicture and then
runs the Stretch function... my control doesn't know the bitmap size.

Thank you for any help you may provide !

Dick B

Private Sub StretchMSPic()

Picture1.AutoRedraw = True: Picture1.ScaleMode = 3
Picture2.AutoRedraw = True: Picture2.ScaleMode = 3

SourceW = 50 <--- test model capture, desktop top/left corner
SourceH = 50
SourceX = 0
SourceY = 0

Desktop = GetDesktopWindow
DesktopDC = GetDC(Desktop)

BitBlt Picture2.hdc, 0, 0, _
SourceW, _
SourceH, _
DesktopDC, _
SourceX, _
SourceY, _

Picture1.Picture = Nothing

DestinationW = Picture1.ScaleWidth
DestinationH = Picture1.ScaleHeight

StretchBlt Picture1.hdc, 0, 0, _
DestinationW, _
DestinationH, _
Picture2.hdc, 0, 0, _
SourceW, _ <--- problem static solution not dynamic
SourceH, _ <---


End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: VB6 Picture Box, picture width and Height

#2 bytelogik  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 218
  • Joined: 06-October 09

Re: VB6 Picture Box, picture width and Height

Posted 17 June 2010 - 10:54 PM


If you are not getting the image size by any means, try the following trick.
Use a dummy PictureBox Control and set it's AutoSize property to true,Appearance to 0, and BorderStyle to 0. This will enable the picture box to resize itself according to the image size.
Now you can straight away get the image size by retrieving the Picture Width or ScaleWidth, whatever you are using. You can set the Visible property of the dummy PictureBox to False, if you want to.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#3 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: VB6 Picture Box, picture width and Height

Posted 17 June 2010 - 11:58 PM

Dim P As stdPicture
Set P = LoadPicture(PathFileName)
MsgBox P.Width & "x" & P.Height

Good Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1