I am receiving feedbacks that several devices have problems while executing this code:
Manifest:
This works on all my samsung devices, but.. :€
B4X:
Sub Process_Globals
Dim ImageChooser As ContentChooser
End Sub
Sub btnUp_Click
Dim q As Int
q= Msgbox2("Upload?","Upload a new picture?","Choose","","Cancel", Null)
If q = DialogResponse.POSITIVE Then
If busyService.serviceStarted = 0 Then
StartService(busyService)
End If
ImageChooser.show("image/*", "Choose image")
Else If q = DialogResponse.NEGATIVE Then
ToastMessageShow("Operation cancelled", True)
Else If q = DialogResponse.CANCEL Then
ToastMessageShow("Operation cancelled", True)
End If
End Sub
Sub imgChooser_Result(Success As Boolean, dir As String, FileName As String)
If Success Then
Try
RandFileName = RandomString(70,True,True,True) & "-" & Rnd(0001,9999) &"-"& Rnd(3350,8721) &"-"& Rnd(1223,3321) & "-" & static_functions.phone_ID & ".jpg"
File.Copy(dir,FileName,File.DirInternal&"/MYFOLDER/",RandFileName)
FitCenterBitmap(profile_picture, RandFileName)
StopService(busyService)
Catch
Log(LastException.Message)
End Try
Else
ToastMessageShow("There was an errror while processing your image, please try again", True)
End If
End Sub
Sub FitCenterBitmap(Imv As ImageView, FileName As String)
Private bmp As Bitmap = LoadBitmapSample(File.DirInternal&"/MYFOLDER/", FileName,200dip,200dip)
Private cvs As Canvas
cvs.Initialize(Imv)
Dim rectDest As Rect
Dim delta As Int
If bmp.Width / bmp.Height > Imv.Width / Imv.Height Then
delta = (Imv.Height - bmp.Height / bmp.Width * Imv.Width) / 2
rectDest.Initialize(0, delta,Imv.Width, Imv.Height - delta)
Else
delta = (Imv.Width - bmp.Width / bmp.Height * Imv.Height) / 2
rectDest.Initialize(delta, 0, Imv.Width - delta, Imv.Height)
End If
cvs.DrawColor(Colors.Black)
cvs.DrawBitmap(bmp, Null, rectDest)
Dim out As OutputStream
out=File.OpenOutput(File.DirInternal&"/MYFOLDER/", FileName, False)
bmp.WriteToStream(out,100,"JPEG")
out.close
Imv.Invalidate
'picChanged = 1
End Sub
Manifest:
B4X:
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
This works on all my samsung devices, but.. :€