View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default PointsToScreenPixels Documentation Incorrect

I'm not sure how to get dimensions of an image on a web page. No doubt
there's a way, otherwise maybe download the image to file. Thereafter a
couple of completely different approaches to get its size here -

http://tinyurl.com/2gzgck

(sizes of some other image types besides gif can also be read from file)

Were you referring to the PixelsPerInch property when you mentioned an

"API
to confirm?"


I forgot about that, but had in mind something like this

Option Explicit

Public Declare Function GetDC Lib "user32" _
(ByVal hwnd As Long) As Long
Public Declare Function ReleaseDC Lib "user32" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, ByVal nIndex As Long) As Long

Private Const LOGPIXELSX As Long = 88&
Private Const LOGPIXELSY As Long = 90&

Function Points2Pixels(ByVal ptX As Single, ByVal ptY As Single, _
pixX As Long, pixY As Long) As Long
Dim hdc As Long
Static bGotDPI As Boolean
Static nX, nY As Long
Const PPI As Long = 72&

' typically nX & nY will return 96

If Not bGotDPI Then
hdc = GetDC(0)
nX = GetDeviceCaps(hdc, LOGPIXELSX)
nY = GetDeviceCaps(hdc, LOGPIXELSY)
hdc = ReleaseDC(0, hdc)
bGotDPI = True
End If

pixX = ptX * nX / PPI
pixY = ptY * nY / PPI

End Function

Sub test()
Dim px As Long, py As Long
Dim wdPnt As Single, htPnt As Single
Dim zm As Long
Dim wdPixels As Long, htPixels As Long

zm = ActiveWindow.Zoom
'may or may not want to cater for zoom depending needs
With Selection
wdPnt = .Width * zm / 100
htPnt = .Height * zm / 100
End With

Points2Pixels wdPnt, htPnt, px, py

MsgBox "points / pixels" & vbCr & _
"Width: " & wdPnt & " / " & px & vbCr & _
"Height: " & htPnt & " / " & py

End Sub

Regards,
Peter T

"Lazzaroni" wrote in message
...
Peter:

Thanks for your help.

You're right. PointsToScreenPixel is definitely not what I am looking for.

I download images to a spreadsheet as thumbnails. I am trying to

streamline
the process as much as possible by determining the maximum width and

height
of the image in pixels based on the target cell's dimensions before
downloading the image. I send the size to a client-side thumbnail

application
using a .php URL. That way the image is pre-sized for display in the

sheet,
and I am not downloading any more than I have to.

For example:
sThumbLink = sURL & Cells(1, 1).Value & "&w=" & lCellWidth & "&h=" &
lCellHeight
ActiveSheet.Shapes.AddPicture(sThumbLink, msoTrue, msoFalse, lCellLeft,
lCellTop, lCellWidth, lCellHeight)

Were you referring to the PixelsPerInch property when you mentioned an

"API
to confirm?"

Now if I could just figure out how to change the source path of the
LinkedPicture to that .php URL after the image has been loaded into the
spreadsheet so that if the spreadsheet is closed and reopened, Excel knows

to
look on the Internet for my linked image instead of on my hard drive. But
that's a different thread:


http://www.microsoft.com/communities...aspx?dg=micros
oft.public.excel.programming&tid=6babdee1-2392-439c-8f15-e9f98b066d4e

Thanks again for your help.