Android: Hardcode images with paths

1k views Asked by At

I am working on an a simple android application that stores objects in an array, and displays them to the user via a listview. Each object contains a photo and a single text field. For demonstration purposes, I would like to pre-populate this array with some hardcoded objects.

The trouble is that the images are typically acquired through the camera interface, and each object only stores the path to that image. I can add the hardcoded images as drawables, but then they don't have a file path. I could when the app is initialized, convert the drawables to bitmaps and save the bitmaps to the SD card, but that seems too complicated to be the correct answer...

Any ideas on the best way to get these images into file storage so that I refer to them via their URIs?

Thanks!

2

There are 2 answers

0
Larry Schiefer On

When you create your views in your adapter, have a ImageView in your layout and use a loader or custom AsyncTask to load the image in the background and have it update the ImageView instance once it has the data.

0
Robert Rowntree On

check the background from this on loading images from the network.

You acquire images from the camera but notice that when you do a resource chooser where mimetype = img/*, the selector just merges local camera(gallery) storage with other photo, content providers. An example of common chooser for photos is in 'Evernote' where you go to the composer view with the 2X2 grid and touch the 'attachment' icon... thats a photo chooser...

In other words , it helps to understand the general practice for managing photos and for presenting them in imageViews.

Typically, there is a lazyLoader that has an interface with args for the imgView and the URI of the image source. Under the covers on a call to 'loadImage(view, uri), the implementation checks the following:

is the bitmap already in a memCache?

the local file , that backs the bitmap, does it exist in the folder reserved for this purpose?

if none of above, go get the array of bytes for the img from across the network ( or in your case , get bytes from camera ).

Even though your question is a little different , IMO , the standard practices for images may apply and you may want to adapt one of the many libs for image presentation to your specific requirements.