Android Question Need help on ContentChooser problem...

Serway

Member
Licensed User
Longtime User
Hi all,

When using ContentChooser to select an image on phone gallery, Erel said on post : https://www.b4x.com/android/forum/threads/contentchooser-crash.60625/#post-382287
You don't need to copy the file. You can load it from its original location.
Use LoadBitmapSample instead of LoadBitmap.

So i use :

Picture = LoadBitmapSample(Dir,FileName,630dip,630dip)
and the result is an image half displayed like in attached file.

Dir value = ContentDir
Filename value = content://com.android.externalstorage.documents/document/3039-6331%3ADCIM%2FCamera%2F20160907_215250.jpg

If i use the GetPathFromContentResult sub ( https://www.b4x.com/android/forum/t...dia-files-returned-from-contentchooser.39313/ )
to save the file, the file is not found.

Is anyone an idea how to solve this ?

Thanks the team for any help.

Thierry
 

Attachments

  • 5_S_1538756083990.jpg
    5_S_1538756083990.jpg
    20.2 KB · Views: 274

npsonic

Active Member
Licensed User
Hi all,

When using ContentChooser to select an image on phone gallery, Erel said on post : https://www.b4x.com/android/forum/threads/contentchooser-crash.60625/#post-382287
You don't need to copy the file. You can load it from its original location.
Use LoadBitmapSample instead of LoadBitmap.

So i use :

Picture = LoadBitmapSample(Dir,FileName,630dip,630dip)
and the result is an image half displayed like in attached file.

Dir value = ContentDir
Filename value = content://com.android.externalstorage.documents/document/3039-6331%3ADCIM%2FCamera%2F20160907_215250.jpg

If i use the GetPathFromContentResult sub ( https://www.b4x.com/android/forum/t...dia-files-returned-from-contentchooser.39313/ )
to save the file, the file is not found.

Is anyone an idea how to solve this ?

Thanks the team for any help.

Thierry
What are you doing when image is selected? It almost seems like you are blocking main thread and thats the result.
 
Upvote 0

Serway

Member
Licensed User
Longtime User
Hi, Thanks Erel and Npsonic,

@Erel :
Yes sure, original image is correct (you can see it on item 4 attached file)
Application for choosing image is by default ... open with dialog.
So, from B4A :

Synoptic (Debug on French Samsung S7 Edge) :

[Process_Globals sub]
Private chooser As ContentChooser

[Select sub]
chooser.Initialize("chooser")
chooser.Show("image/*","Select image ..")

[Intent...]
>> Open with dialog (Attached file number 1)
Select SD Card
>> SD Card (Attached file number 2)
Select DCIM
>> DCIM (Attached file number 3)
Select CAMERA
>> CAMERA (Attached file number 4)
First image selected

[chooser_Result sub]
Dim lastPicture As B4XBitmap
lastPicture = LoadBitmapSample(Dir,FileName,630dip,630dip)

LastPicture show and save as half displayed.

@npsonic :
See Synoptic.
Main thread is not blocked.

Many thanks for your help.
Thierry

1.jpg
2.jpg
3.jpg
4.jpg
 
Upvote 0

Serway

Member
Licensed User
Longtime User
Thanks Erel.

Try to copy the file before loading as described :
File.Copy(Dir,FileName, File.DirInternal, "temp.jpg")

Dir = ContentDir
Filename = content://com.android.externalstorage.documents/document/3039-6331%3ADCIM%2FCamera%2F20160907_215250.jpg

And get this error :
(Exception) java.lang.Exception: java.io.IOException: read failed: EIO (I/O error)

As mentionned in first post, if i try to save the file like this :
GetPathFromContentResult sub ( https://www.b4x.com/android/forum/t...dia-files-returned-from-contentchooser.39313/ )
the file is not found.

So, after getting image from Gallery, Exif information must not be loose (with WriteToStream) cause i need to know orientation with ExifInterface lib.

Any idea ?
 
Upvote 0

npsonic

Active Member
Licensed User
Use code tags, so it's easier to read your answers [ CODE] [/CODE]

Check this quick example how you could do it easier, maybe it will help you.

Remember to add AddPermission(android.permission.READ_EXTERNAL_STORAGE) into manifest.
B4X:
Sub Process_Globals
    Private cc As ContentChooser
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    cc.Initialize("CC")
    cc.Show("image/*", "Choose image")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub CC_Result (Success As Boolean, Dir As String, Filename As String)
    If Success Then
        Log("success")
        Dim bd As BitmapDrawable
        bd.Initialize(LoadBitmapSample(Dir,Filename,Activity.Width,Activity.Height))
        Activity.Background = bd
    Else   
        Log("failed")
    End If
End Sub
 
Upvote 0

Serway

Member
Licensed User
Longtime User
Thanks Npsonic,

You're right for [ CODE] [/CODE], i will do it.
I have try your code but same ... image displayed not complete.
 
Upvote 0

npsonic

Active Member
Licensed User
Example works perfectly on my phone (OnePlus 3), so there must be something strange going on in your phone.
Just can't figure out yet what it could be.
 
Upvote 0

npsonic

Active Member
Licensed User
How much free ram do you have left on your device?
 
Upvote 0

npsonic

Active Member
Licensed User
Free RAM : 1,6 Go.
Have you try like in post 4 ?
I don't see why it wouldn't work.
You can test my example with File.Copy like Erel wrote, but I don't know if it makes any difference.

B4X:
Sub CC_Result (Success As Boolean, Dir As String, Filename As String)
    If Success Then
        Log("success")
        Wait For (File.CopyAsync(Dir, Filename, File.DirInternal, Filename)) Complete (Success As Boolean)
        If Success Then
            Dim bd As BitmapDrawable
            bd.Initialize(LoadBitmapSample(File.DirInternal,Filename,Activity.Width,Activity.Height))
            Activity.Background = bd
        Else
            Log("failed")
        End If
    Else
        Log("failed")
    End If
End Sub

This thread needs some more experienced developer contribution.
 
Upvote 0

Serway

Member
Licensed User
Longtime User
Thanks for your time and help

Error : (Exception) java.lang.Exception: java.io.IOException: read failed: EIO (I/O error)
with File.Copy or File.CopyAsync (like in post 6)
 
Upvote 0

npsonic

Active Member
Licensed User
Thanks for your time and help

Error : (Exception) java.lang.Exception: java.io.IOException: read failed: EIO (I/O error)
with File.Copy or File.CopyAsync (like in post 6)
Do you run app in Release or in Debug mode? Try example with Release mode and remove old example from phone before installing, also check that app has storage permission.

Are your images on your sdcard in any chance? If so, try to copy one image to devices internal memory and try to open it.

This might be the case of broken sdcard.
 
Upvote 0
Top