Android Question [B4x] What is the most effective way to determine height and width of an imagefile?

fredo

Well-Known Member
Licensed User
What do you need it for?
B4X:
[main module]
private Sub c6IconLs_Click
    MainMasterShowImage(File.DirAssets, "stromverlauf.jpg")   
End Sub

Private Sub MainMasterShowImage(Dir As String, FileName As String)
    ' Erel --> https://www.b4x.com/android/forum/threads/b4x-use-webview-to-show-large-images.102910/#content
    MainMasterWv.Visible = True   
    #if B4A
        Dim jo As JavaObject = Me
        jo.RunMethod("zoom", Array(MainMasterWv))
    #End If
    MainMasterWv.LoadHtml(Starter.mh.HtmlImageString(Starter.xui.FileUri(Dir, FileName), 100%x, 100%y)) 
End Sub


[myhelper class]
public Sub HtmlImageString(ImageFileName As String, Width As Int, Height As Int) As String
    Return $"
                <html>
                    <head>
                        <style Type="text/css"> 
                            img {
                                    position: absolute;
                                    width: ${Width}px;
                                    height: ${Height}px;
                                    left: 50%;
                                    top: 50%;
                                    margin-left: -${Width/2}px;
                                    margin-top: -${Height/2}px;
                                }
                        </style> 
                    </head> 
                    <body> 
                        <img src="${ImageFileName}"> 
                    </body> 
                </html>
                "$
End Sub
A selected image should be displayed full screen and zoomable.

An HtmlString is generated that takes the size of the image into account.

Since there is no essential knowledge in Css/Html, the use of height and width was chosen as a possibly simple approach.
 
Top