Hi All,
i try copy file image that i choose from Image Gallery.
when i debug Sub imgChooser_Result(Success As Boolean, Dir As String, FileName As String)
Dir is blank (Dir = '') and FileName = /storage/emulated/0/DCIM/Camera/IMG_20160525_142639.jpg
when i execute
File.Copy(Dir, FileName, File.DirRootExternal, "1.jpg")
it cannot copy the file
then i search from the forum to use file.copy2
but still it cannot copy the file because these is no Dir value, only have FileName
here is the code
What is wrong with my code?
Please help me
Thanks
i try copy file image that i choose from Image Gallery.
when i debug Sub imgChooser_Result(Success As Boolean, Dir As String, FileName As String)
Dir is blank (Dir = '') and FileName = /storage/emulated/0/DCIM/Camera/IMG_20160525_142639.jpg
when i execute
File.Copy(Dir, FileName, File.DirRootExternal, "1.jpg")
it cannot copy the file
then i search from the forum to use file.copy2
but still it cannot copy the file because these is no Dir value, only have FileName
here is the code
B4X:
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 cr As ContentResolver
cr.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 = cr.Query(Uri1, Proj, "_id = ?", Array As String(id), "")
Else
Uri1.Parse(UriString)
Cursor1 = cr.Query(Uri1, Proj, "", Null, "")
End If
Cursor1.Position = 0
Dim res As String
res = Cursor1.GetString("_data")
Cursor1.Close
Return res
End Sub
Sub imgChooser_Result(Success As Boolean, Dir As String, FileName As String)
Dim nil_scale As Double
Dim gambar As Bitmap
Dim s As StringFunctions
Dim path1 As String
If Success Then
Dim realPath As String = GetPathFromContentResult(FileName)
path1 = s.Right(realPath,5)
If path1 <> "1.jpg" Then
'If the user used a file manager to choose the image
If FileName.StartsWith("/") Then
Dim in As InputStream = File.OpenInput(Dir, FileName)
Dim out As OutputStream
out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
File.Copy2(in, out)
Else
File.Copy(Dir, FileName, File.DirRootExternal, "1.jpg")
End If
End If
Else
ToastMessageShow("No image selected", True)
End If
End Sub
What is wrong with my code?
Please help me
Thanks