Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the width and hieght of an image opened by CommonDialogue?? 1

Status
Not open for further replies.

rahmanjan

Programmer
Apr 13, 2003
180
0
0
AU
Hi all,

Happy new year to everyone!

I am opening images via Common Dialogue Control and then loading them into Picture boxes / Image control. What I want to do is before loading the image I want to know the actual Width and Hight of the image.

Is there a way to identify it before further processing of the image?

regards

RA
 
enlarging an image is like this
Image1.Height = Image1.Height + 150
Image1.Width = Image1.Width + 200

so when you open the picture in the common dialogue you will want to have a form pop up with 2 textfields that the user fills in for the size

on the form1 code you'll need osmething like this

Image1.Height = Image1.Height + form2.text1.text
Image1.Width = Image1.Width + form2.text2.text
this will set the size what the user wants


sign05.GIF
sign05.GIF
sign05.GIF
Uprocker2
sign06.gif
sign06.gif
sign06.gif
 
Here's one way (although it does still involve loading the image):

Option Explicit

Private Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
Private Const HIMETRIC_PER_INCH = 2540
Private Const TWIPS_PER_INCH = 1440

Private Sub Command1_Click()
Dim myPicture As IPictureDisp

Set myPicture = LoadPicture("c:\test.bmp") ' You would be getting filename from common dialog instead

' Get result into pixels
' You could alternatively use the MapMode method to do this
Debug.Print MulDiv(myPicture.Width, 1440, HIMETRIC_PER_INCH) / Screen.TwipsPerPixelX
Debug.Print MulDiv(myPicture.Height, 1440, HIMETRIC_PER_INCH) / Screen.TwipsPerPixelY
End Sub
 
Thanks StrongM,

I think you are in the right track ... and i hope it will work for me.

I give you a *Start* for it.

What I want to is I am opening this pic using commondialogue control the picture is loaded in a pcture box however user has the option to click on the pic and enlarge it so I open another pop up form and resize it or its picture box based on the Hieght and Width of opned pic.

Regards

RA
 
Hi StrongM,

A small issue here ... this code is giving me the size of the image in Pixels however, Picturebox and Forms
controls are in standard option (Inches???) ... I tryed to changed the ScaleMode of the picture box to Pixel
(I don't know if this is the right property to be changed) but it didn't work by my code thought I did it
in design time.

I did something like picture1.scalemode=VBPixel (doesn't work) PIXEL (doesn't work) "PIXEL" (doesn't work)

So the goal is to get the size of the image by the code you provided and then change the size of pop up form
and picturebox according to the image size.

Do I need to change PIXEL back to Inches or something here?

regards

RA
 
Default measurement for Forms is Twips. There are 1440 Twips to the logical inch. To change a Forms ScaleMode to Pixels:

Me.ScaleMode = 3


You can convert twips to Pixels using the Screen.TwipsPerPixelX and Screen.TwipsPerPixelY properties of the Screen object



________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

For tsunami relief donations

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
If you don't divide by Screen.TwipsPerPixelX and Screen.TwipsPerPixelY in the code I provided, then you will get the dimensions in twips instead of pixels
 
Wow great StrongM ...

I was kind of confused after John's message ...

That sorts everything ...

Another *star*? ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top