View an image in WebBrowser1 and resize it

Viewed 138

I created, through a UserForm in Excel, a simple image viewer; the image is displayed by means of a WebBrowser1 control. I am looking for ways to resize the image to fit the size of the control and / or resize the control to match its size to those of the images. I tried to derive the image dimensions with

 With Me.WebBrowser1
     .Navigate ImagePath
     .Width = .Document.images (1) .Width
     .Height = .Document.images (1) .Height
 End With

but it seems that you cannot access from VBA to

WebBrowser1.Document.images

Does anyone know of a way to do this?

Thank you very much, this worked (cFiles (Current) is a File object)

 With Me.WebBrowser1
     .Navigate "about: blank"
     Do While .ReadyState <> READYSTATE_COMPLETE
         DoEvents
     Loop
     .Document.Write "<body style = 'background-color: buttonface; overflow: hidden;'> <img style = 'width: 100%;' src = '"& cFiles (Current) .Path &"'> </body> "

I am left with the problem of detecting the height and width of the image in order to center the image in the UserForm. So far I have used a hidden Image control with AutoSize = True but it is an extremely inelegant solution and with some images (like png) it doesn't work.

0 Answers
Related