PDA

View Full Version : Getting information about inserted/pasted images



joe324
12-11-2008, 08:57 AM
Hi,

I'm trying to work out if it's possible to retrieve detailed information from pcitures that have been pasted into word or inserted with InsertPicture.

Ideally, we want to prevent a user from inserting/pasting certain images into word depending on things like file size etc.

Currently we know we can look at all the InlineShape and Shape objects in the document and get their height and width (although it seems only after they have gone into the document, and the height and width is probably not the original height/width, although I haven't checked)

I would have thought Word would know some more details about the image we could use else there's nothing to stop a user inserting a small in size but large in file size image.

Joe

fumei
12-11-2008, 12:34 PM
"I would have thought Word would know some more details about the image we could use else there's nothing to stop a user inserting a small in size but large in file size image."

Nope, it doesn't, and yes, they can. Although I am curious about "small in size but large in file size".

Caveat to the first comment. Yes, it could...depending on precisely how the image was being put in the document. This is tied to:

"although it seems only after they have gone into the document"

Well yes. Unless you are inserting the files via a specific type of code, Word knows nothing about the files...and does not care.

"Ideally, we want to prevent a user from inserting/pasting certain images into word depending on things like file size etc."

No can do. Not unless you want to rewrite the Insert > Picture instruction, and even then it would be tricky. As for copy/paste...nope.

joe324
12-12-2008, 03:51 AM
Thanks for the reply

Sorry I wasn't clear with some of my post. With "small in size but large in file size" I meant someone could paste a full size screen shot and word will resize it to fit on the page, so the size reported by word might be smaller. Or they could insert a 10MB image, and word would resize to fit the page.

"Well yes. Unless you are inserting the files via a specific type of code, Word knows nothing about the files...and does not care."

We were looking at the EditPaste function and whether we could check details of the clipboard and find out about the image before we do the paste.

fumei
12-12-2008, 11:00 AM
You can not get image attributes like file size from the clipboard. AFAIK the information in the clipboard vis-a-vis a graphic is a straight-forward byte-array. In other words, there is NO file information, as there is no file.

As for images pasted in, once it is in the document, you can use FormatPicture to see Original Height and Original Width under the Size tab. However....I know of no way to actually get those values via code, except as a calculation. Word keeps that information to itself apparently, as they do not seem to be exposed to VBA. If they were, you could use them - although after the fact (after it is pasted).

To get the original values (height and width) do this, assuming we are working with the first InlineShape:
Dim oIn As InlineShape
Set oIn = ActiveDocument.InlineShapes(1)
MsgBox "Original Height is " & _
oIn.Height * 100 / oIn.ScaleHeight

Note that there is going to be a bit of sloppiness due to the way VBA handles numbers.

ScaleHeight is a percentage.

In my test for this, if I use Reset to make the pasted image the original size, Word reports (afterwards) the .Height as 576.6.

The initial .Height was 324, with a ScaleHeight (in the dialog) = 56. However, getting the actual ScaleHeight by code, it is 56.3.

So.....

oIn.Height * 100 / oIn.ScaleHeight = 576.6

Further, once "Reset", ScaleHeight = 100.1%

My point being is that due to the inaccuracy of the floating-point used, there is a bit of slop. Also, again, this kind of value determination (and/or adjustment) must be done after the fact. You can not get this information prior to the paste.