hi
i would like to get the filesize from content chooser and if the size if bigger then x i will resize it. how can i do that? i am trying it like this but i always get 0 in logs
logs:
i would like to get the filesize from content chooser and if the size if bigger then x i will resize it. how can i do that? i am trying it like this but i always get 0 in logs
B4X:
Sub cr_Result (Success As Boolean, Dir As String, FileName As String)
Wait For(checkifDirecteryexistsandcreate) Complete (Result As Boolean)
If Result = False Then Return
Try
If Success Then
' Dim targetsize As Long = 300*1024
Log("#######")
Log(GetPathFromContentResult(FileName))
Log(File.Size(GetPathFromContentResult(FileName).Replace("/" & FileName,""),FileName))
' Dim ratio As Float = (targetsize / orgsize) * 100
' If orgsize > targetsize Then
' End If
Dim ins As InputStream = File.OpenInput(Dir, FileName)
Dim bmp As Bitmap
bmp.Initialize2(ins)
Dim out As OutputStream
out = File.OpenOutput(File.DirInternal, "userimg.png", False)
bmp.WriteToStream(out, 100, "JPEG")
out.Close
Log("#######")
Log(File.Size(File.DirInternal, "userimg.png"))
loaduserinfo(False,True) 'load image
End If
Catch
Log(LastException)
End Try
End Sub
Sub GetPathFromContentResult(UriString As String) As String
If UriString.StartsWith("/") Then Return UriString 'If the user used a file manager to choose the image
Dim Cursor1 As Cursor
Dim Uri1 As Uri
Dim Proj() As String = Array As String("_data")
Dim crs As ContentResolver
crs.Initialize("")
If UriString.StartsWith("content://com.android.providers.media.documents") Then
Dim i As Int = UriString.IndexOf("%3A")
Dim id As String = UriString.SubString(i + 3)
Uri1.Parse("content://media/external/images/media")
Cursor1 = crs.Query(Uri1, Proj, "_id = ?", Array As String(id), "")
Else
Uri1.Parse(UriString)
Cursor1 = crs.Query(Uri1, Proj, "", Null, "")
End If
Cursor1.Position = 0
Dim res As String
res = Cursor1.GetString("_data")
Cursor1.Close
Return res
End Sub
logs:
** Activity (main) Resume **
#######
/storage/3632-3738/DCIM/Camera/20180608_105511.jpg
0
#######
2968068