How you can use the chooser only to open image files (. jpg, png, jpeg, etc.)?
If you accidentally click on a file with a different extension (.txt, for example), the chooser crashes.
:sign0148:
If you accidentally click on a file with a different extension (.txt, for example), the chooser crashes.
B4X:
Sub Process_Globals
Dim loadpicture As ContentChooser
End Sub
Sub Globals
Dim pnlempty As Panel
Dim image1 As ImageView
Dim bitmap1,bitmap2 As Bitmap
Dim Canva1 As Canvas
Dim RectDest As Rect
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
loadpicture.Initialize("chooser")
loadpicture.Show("image/*", "Choose image")
End Sub
Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
If Success Then
bitmap1.InitializeSample(Dir, FileName, pnlempty.Width, pnlempty.Height)
bitmap2.InitializeMutable(pnlempty.Width,pnlempty.Height)
Canva1.Initialize2(bitmap2)
RectDest.Initialize(0, 0, pnlempty.Width, pnlempty.Height)
Canvas1.DrawBitmap(bitmap1, Null,RectDest)
empty.Bitmap = bitmap2
End If
End Sub