Getting the size of an InlineShape

J

Jeff Hall

I have 3 identical pictures linked to a W2000 document
testpic.PNG
testpic.JPG
testpic.GIF

I am getting the original picture size as follows

w = Selection.InlineShapes(1).Width
sw = Selection.InlineShapes(1).ScaleWidth
h = Selection.InlineShapes(1).Height
sh = Selection.InlineShapes(1).ScaleHeight

' Original Size of Picture in pixels
ow = Round(w / sw * 100, 0)
oh = Round(h / sh * 100, 0)

However, although Word calculates the size of the PNG correctly, it thinks
the JPG and the GIF are exactly 75% of the size of the PNG

PNG 315 x 284 OK
JPG 236 x 213 Wrong
GIF 236 x 213 Wrong

Any ideas what's wrong?
Interestingly, the PNG displays too large in the document, whereas the other
two are displayed at the correct size, even though the Format|Picture dialog
shows them all at 100% scaling.
 
J

Jezebel

Not sure if this is the problem here, but Word seems to recalculate the size
of an image by dividing the size in pixels by the screen resolution. I've
found that for some formats, if the original image is 10cm wide at 300 dpi,
Word will treat it as 32 cm wide at 96 dpi.
 
D

Doug Robbins - Word MVP

Hi Jeff,

I am not sure if this is of use to you, but here's a bit of code from one of
my applications that is used to re-size a graphic to fit the dimensions of
the cell into which it is inserted:

'Re-size logo
oheight = myDoc.Tables(1).Cell(5,
2).Range.InlineShapes(1).Height
owidth = myDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1).Width
If oheight > InchesToPoints(1.6) Then
With myDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1)
.Height = InchesToPoints(1.6)
.Width = owidth * InchesToPoints(1.6) / oheight
End With
End If
If oheight < InchesToPoints(0.68) Then
With myDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1)
.Height = InchesToPoints(1.6)
.Width = owidth * InchesToPoints(1.6) / oheight
End With
End If
oheight = myDoc.Tables(1).Cell(5,
2).Range.InlineShapes(1).Height
owidth = myDoc.Tables(1).Cell(5,
2).Range.InlineShapes(1).Width
If owidth > InchesToPoints(1.6) Then
With myDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1)
.Width = InchesToPoints(1.6)
.Height = oheight * InchesToPoints(1.6) / owidth
End With
End If

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
J

Jeff Hall

I wondered about whether there is a connection with the default units, so I
now store the existing Options.MeasurementUnit and then set
Options.MeasurementUnit = wdPoints.

I then do the sums and finally restore the default MeasurementUnit

Only one out of three epictures (in the same document) sizes correctly.
The irritating thing is that, when I tried it on other documents with
different pictures, it wasn't always the PNG that sized incorrectly,
although the error was always a factor of 0.75.

I'm thinking it may be something to do with the way the picture was
originally stored in the document? ANY suggestions would be welcome, no
matter how unlikely they may seem. I really need to solve this one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top