Based on the Threat in the following link
How to create FillImageToView in a XUI Slider?
I have tried the following code
And Use this code
And Get this error messages
How to create FillImageToView in a XUI Slider?
I have tried the following code
B4X:
Sub ImageSlider1_GetImage (Index As Int) As ResumableSub
Private ImageView1 As ImageView
ImageView1.Initialize("ImageView1")
Wait For (CallSub2(Starter, "DownloadImage", Index)) Complete (x As B4XBitmap)
FillImageToView(x, ImageView1)
Return x
End Sub
And Use this code
B4X:
Sub FillImageToView(bmp As B4XBitmap, ImageView As B4XView)
Dim bmpRatio As Float = bmp.Width / bmp.Height
Dim viewRatio As Float = ImageView.Width / ImageView.Height
If viewRatio > bmpRatio Then
Dim NewHeight As Int = bmp.Width / viewRatio
bmp = bmp.Crop(0, bmp.Height / 2 - NewHeight / 2, bmp.Width, NewHeight)
Else if viewRatio < bmpRatio Then
Dim NewWidth As Int = bmp.Height * viewRatio
bmp = bmp.Crop(bmp.Width / 2 - NewWidth / 2, 0, NewWidth, bmp.Height)
End If
ImageView.SetBitmap(bmp.Resize(ImageView.Width, ImageView.Height, True))
End Sub
And Get this error messages
B4X:
Error occurred on line: 330 (Main)
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:1074)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1041)
at android.graphics.Bitmap.createBitmap(Bitmap.java:991)
at android.graphics.Bitmap.createBitmap(Bitmap.java:912)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:782)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Resize(CanvasWrapper.java:568)
at anywheresoftware.b4a.objects.B4XViewWrapper$B4XBitmapWrapper.Resize(B4XViewWrapper.java:617)
at exemplo.menu.branco.main._fillimagetoview(main.java:1043)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1761)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7094)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)