linked image width and height in pixels?

  • In WPTools 5, I had a dialog popup which showed the linked image properties. I would show the presented size using WPRextObj.Width / 1440.0 and WPTextObj.Height / 1440. I would also show the actual image size in pixels using WPTextObj.ObjRef.Picture.Width and WPTextObj.ObjRef.Picture.Height. However, in WPTools 9, WPTextObj.ObjRef.Picture.Width and WPTextObj.ObjRef.Picture.Height return 0. It appears fPicture/fGraphic is nil, so Vcl.Graphics returns 0. for both TPicture.GetWidth and TPicture.GetHeight.

    And yes, I believe the linked image has been loaded since it is visible in the editor. Is there a new way to get the image size in pixels or do I really not have it loaded? I load it on the RequestHTTPImage event using TextObject.LoadObjFromStream(ExtractFileExt(vReportImage.Name), vReportImage.Image);

    I did not load linked images this way in WPTools 5, so that is different and might have something to do with it. For example, In WPT5 I loaded images from a file in a function but now I load them from a stream in the RequestHTTPImage event. They are JPG images.

    Eric

    • Offizieller Beitrag

    The use of ObjRef.Picture.Width and ObjRef.Picture.Height is not recommended. Picture is a sole container for the bitmap non not the owning object.

    WPTextObj.Width and WPTextObj.Height is the required size of the image in twips.

    The functions ContentsWidth and ContentsHeight return the actual, not stretched size of the loaded image in twips.

  • But ContentsWidth and ContentsHeight are in twips, correct? I want the actual physical bitmap dimensions in pixels right out of the image file.

    When I use the following MulDiv, it correctly provides the actual bitmap size in pixels, but I'm not sure this is always going to be the physical image size under all High DPI and various screen resolutions... maybe it is but I just don't know because it is referencing twips in the equation. I just want the bitmap dimensions as defined in the bitmap itself, not something that is being computed.

    Code
    vPixelWidth := MulDiv(fWPTextObj.ObjRef.ContentsWidth, Screen.PixelsPerInch, 1440);
    vPixelHeight := MulDiv(fWPTextObj.ObjRef.ContentsHeight, Screen.PixelsPerInch, 1440);
    • Offizieller Beitrag

    If you really need the physical size you need to check what image is loaded in Graphic or in the stream. The unit wpobj_image will give you an idea. The question is what do you need those values vor?

    The way TWPObject.GetContentsWH works it usually takes the screen resolution as reference, but it also limits the size to a page size since bitmaps could be really big otherwise since they do not store a dpi value, at least jpeg does not.

  • I don't actually need those pixel values for much of anything.other than for the user's benefit and support reasons. When a user adds an image to a report, we automatically scale photos (vs diagrams) down to a reasonable size so their PDF report size is manageable for emailing. Sometimes we get a question as to why their reports are so big, so we ask what they configured their image scaling to be in our app. And so to confirm it is all working and that they are not importing using a different method (diagram vs photo), we right click the image in the report and view its properties to see what the actual image size in pixels is which tells us something about how they added the image and if it had been scaled down or not.

    In our old app using WPT5, the Picture.Width and Height used to return the pixel dimensions, but in the WPT9 re-write it is not for some reason. I can use other methods to get the pixel size, like perhaps using ImageEn (which we now use for the image editor), but that seems overkill on my side just to get the pixel dimensions.