Open image in default gallery

grant1842

Active Member
Licensed User
Longtime User
Here's the code I'm using to open an image taken with the camera with the default gallery:

B4X:
Dim i As Intent
   'i.Initialize(i.ACTION_VIEW, "/mnt/sdcard/DCIM/Camera/IMG_20121027_205219.jpg")
   i.Initialize(i.ACTION_VIEW, "mnt/sdcard/DCIM/Camera/IMG_20121027_205219.jpg")
   Log("mnt/sdcard/DCIM/Camera/IMG_20121027_205219.jpg")
   i.SetType("image/*")
   StartActivity(i)
    Log("error:"&I)

When I click the button, the gallery opens and then just force closes itself. I need to open the image in the gallery viewer so it has the options of the gallery. For example, the default installed gallery usually has the options to share, set as, or delete a photo and that's what I need.
 
Last edited:

Dave Fitzpatrick

Member
Licensed User
Longtime User
Try this:

Dim ImageChooser As ContentChooser

ImageChooser.Initialize("imgChooser")

ImageChooser.show("image/*", "Choose image")

Sub imgChooser_Result(Success As Boolean, Dir As String, FileName As String)

if Success then
'do whatever
end if

end sub

- - Dave
 
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
That does bring up the gallery to choose a image, however, when you choose an image it takes you back to your app. I need to open the image in the gallery viewer so it has the options of the gallery. For example, the default installed gallery usually has the options to share, set as, or delete a photo and that's what I need.
 
Upvote 0

grant1842

Active Member
Licensed User
Longtime User
Hmm that is a somewhat decent workaround. I'd like for them to be able to choose the picture so they can see it full sized as well as have the different options.
 
Upvote 0

angelone

Member
Licensed User
Longtime User
Sorry if i resume this old post.

I have to choose an image from image gallery, and set it as background of a button.
How can i get the image file name?


Selectedimage = LoadBitmap(File.Dirofchoosedimage,"choosedimagefilename.jpg")

Button1.SetBackgroundImage(Selectedimage)
 
Last edited:
Upvote 0

angelone

Member
Licensed User
Longtime User
Thank's ergel,

is there an example
 
Upvote 0

angelone

Member
Licensed User
Longtime User
Hi,
thank's a lot for your help.

But i have an erro when I initialize the variable :

Dim ImageChooser As ContentChooser

Compiling code.
Error
Error parsing program.
Error description: Unknown type: contentchooser
Are you missing a library reference?
Occurred on line: 85
Dim ImageChooser As ContentChooser

How can i add reference?
 
Last edited:
Upvote 0

angelone

Member
Licensed User
Longtime User
Sorry... solved :sign0013::sign0013::sign0013:
 
Upvote 0

angelone

Member
Licensed User
Longtime User
Hi, may i pass the name of Imageview in this way?


Dim selectedimage As ContentChooser
selectedimage.Initialize("imgChooser")
selectedimage.show("image/*", "Choose image")

Sub selectedimage_Result (Success As Boolean, Dir As String, FileName As String, ControlName As String)
If Success Then
ControlName.Bitmap = LoadBitmap(Dir, FileName)
ControlName.Gravity = Gravity.FILL
Else
ToastMessageShow("Nessuna Immagine Selezionata", True)
End If
End Sub
 
Upvote 0

angelone

Member
Licensed User
Longtime User
Do not handle the evente Result

Hi,
why this code

B4X:
Sub Set_Button1_Click    
ImageChooser1.Initialize("imgChooser1")
ImageChooser1.show("image/*", "Choose image")

End Sub

do not handle the result event?

B4X:
Sub imgChooser1_Result(Success As Boolean, Dir As String, FileName As String)
    If Success Then 
   pec1.Bitmap = LoadBitmap(Dir, FileName)    
   pec1.Gravity = Gravity.FILL
    Else 
            ToastMessageShow("Nessuna Immagine Selezionata", True) 
    End If 
   End Sub
 
Upvote 0

angelone

Member
Licensed User
Longtime User
in sub globals
Dim ImageChooser1 As ContentChooser
 

Attachments

  • facilitatore.zip
    8.8 KB · Views: 616
Last edited:
Upvote 0
Top