Once you have the IOleObject cast it to either IPicture, or if that fails, to IViewObject2. Then the original size is either IPicture.Width/Height or IViewObject2.GetExtent.
Note it's given in HiMetric and there seems to be application-independent scaling applied; i.e. even if your app is marked DPI-unaware, and even if you use GetDC(hwnd) instead of GetDC(0), the original dimensions returned are scaled according to the Windows system wide scale factor. If you're at 150% multiply by 1.5, for example. At least with IViewObject2, which is the one that worked for my test png.
Where tObj is the REOBJECT after you've successfully called.GetObject.Code:Dim pPic As IPicture Dim szOrig As SIZE Dim szOrigHM As SIZE Set pPic = tObj.poleobj If pPic IsNot Nothing Then szOrigHM.cx = pPic.Width szOrigHM.cy = pPic.Height HiMetricToPixel(szOrigHM, szOrig, hRE) Debug.Print "origdim->IPicture cx=" & szOrig.cx & ",cy=" & szOrig.cy Set pPic = Nothing Else Dim pVO As IViewObject2 Set pVO = tObj.poleobj If pVO IsNot Nothing Then pVO.GetExtent(DVASPECT_CONTENT, -1&, vbNullPtr, szOrigHM) HiMetricToPixel(szOrigHM, szOrig, hRE) Debug.Print "origdim->IViewObject2 cx=" & szOrig.cx & ",cy=" & szOrig.cy Set pVO = Nothing Else Debug.Print "origdim->Neither IPicture nor IViewObject2 available." End If End If




Reply With Quote