Android Question B4XImageView

Sergey_New

Well-Known Member
Licensed User
Longtime User
Please help me determine the coordinates of the green rectangle for images 1.png and 2.png.
scrin.png
 

Attachments

  • temp.zip
    4.5 KB · Views: 123
Solution
Try this code
B4X:
Sub DrawLine
    Dim realheight,realwidth As Float
    photo.Clear
    photo.Bitmap=LoadBitmap(File.DirAssets, spn.SelectedItem)
    l=lbl.Width
    t=lbl.Top+lbl.Height
    w=100%x-lbl.Width-lbl.Width
    h=100%y-lbl.Top-lbl.Height-lbl.Height
    photo.mBase.SetLayoutAnimated(0,l,t,w,h)
    photo.Update
    Dim ratio As Double=photo.Bitmap.width/photo.mBase.Width - photo.Bitmap.Height/photo.mBase.Height
    If ratio>0 Then
        realheight=photo.Bitmap.Height*w/photo.Bitmap.Width
        top=t+h/2-realheight/2+realheight
        l=l+w
    Else
        realheight=t+h
        top=realheight
        realwidth=photo.Bitmap.width*h/photo.Bitmap.Height
        l=l+w/2-realwidth/2+realwidth
    End If...

Sergey_New

Well-Known Member
Licensed User
Longtime User
I drew a line along the bottom border of the rectangle.
B4X:
    top=t+h/2-photo.Bitmap.Height/2+photo.Bitmap.Height
    Dim cvs As Canvas
    cvs.Initialize(Activity)
    cvs.DrawLine(0,top,100%x,top, Colors.red, 1dip)
ln.png
The result is that the line goes slightly above this border.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
And for 2.png the line goes significantly above the bottom border of the rectangle.
 

Attachments

  • temp2.zip
    4.6 KB · Views: 117
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
I drew a line along the bottom border of the rectangle.
B4X:
    top=t+h/2-photo.Bitmap.Height/2+photo.Bitmap.Height
    Dim cvs As Canvas
    cvs.Initialize(Activity)
    cvs.DrawLine(0,top,100%x,top, Colors.red, 1dip)
The result is that the line goes slightly above this border.
This bitmap is scaled. you need to re-calculate its height and width by ratio.

B4X:
Private Sub spn_ItemClick (Position As Int, Value As Object)
    photo.Clear
    photo.Bitmap=LoadBitmap(File.DirAssets, Value)
    photo.Update
    cvs.Initialize(Activity)
    If photo.Bitmap.Height < photo.Bitmap.Width Then
        Dim realheight As Float=photo.Bitmap.Height*w/photo.Bitmap.Width
        top=t+h/2-realheight/2+realheight
        cvs.Initialize(Activity)
        cvs.DrawLine(0,top,100%x,top, Colors.red, 1dip)
    Else
        Dim realwidth As Float=photo.Bitmap.width*h/photo.Bitmap.Height
        Dim ll As Float
        ll=l+(w-realwidth)/2
        cvs.DrawLine(ll,0,ll,100%y, Colors.blue, 1dip)
    End If
End Sub

1.png
2.png
 
Last edited:
Upvote 1

Sergey_New

Well-Known Member
Licensed User
Longtime User
I was too happy too early :(
I checked the work on the Samsung Galaxy S7 device (screen size 1440 x 2560) with different image sizes - everything works correctly.
I decided to check on the Samsung Galaxy S 23 device (screen size 1080 x 2340). When using the 5.png image, the coordinates are determined incorrectly. I attach an example.
How can I fix it?
 

Attachments

  • temp.zip
    20.5 KB · Views: 142
Upvote 0

teddybear

Well-Known Member
Licensed User
Try this code
B4X:
Sub DrawLine
    Dim realheight,realwidth As Float
    photo.Clear
    photo.Bitmap=LoadBitmap(File.DirAssets, spn.SelectedItem)
    l=lbl.Width
    t=lbl.Top+lbl.Height
    w=100%x-lbl.Width-lbl.Width
    h=100%y-lbl.Top-lbl.Height-lbl.Height
    photo.mBase.SetLayoutAnimated(0,l,t,w,h)
    photo.Update
    Dim ratio As Double=photo.Bitmap.width/photo.mBase.Width - photo.Bitmap.Height/photo.mBase.Height
    If ratio>0 Then
        realheight=photo.Bitmap.Height*w/photo.Bitmap.Width
        top=t+h/2-realheight/2+realheight
        l=l+w
    Else
        realheight=t+h
        top=realheight
        realwidth=photo.Bitmap.width*h/photo.Bitmap.Height
        l=l+w/2-realwidth/2+realwidth
    End If
    cvs.DrawColor(Colors.White)
    cvs.DrawLine(0,top,100%x,top, Colors.red, 1dip)
    cvs.DrawLine(l,0,l,100%y, Colors.Blue, 1dip)
End Sub
 
Upvote 0
Solution

Sergey_New

Well-Known Member
Licensed User
Longtime User
teddybear, many, many thanks!
Once again your help helps solve the problem!
Once again, many thanks!
 
Upvote 0
Top