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


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

Private Sub MainMasterShowImage(Dir As String, FileName As String)
    ' Erel -->
    MainMasterWv.Visible = True   
    #if B4A
        Dim jo As JavaObject = Me
        jo.RunMethod("zoom", Array(MainMasterWv))
    #End If
    MainMasterWv.LoadHtml(, FileName), 100%x, 100%y)) 
End Sub

[myhelper class]
public Sub HtmlImageString(ImageFileName As String, Width As Int, Height As Int) As String
    Return $"
                        <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;
                        <img src="${ImageFileName}"> 
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.