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!
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.
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.
Related
This is a different situation. I want to load a image file which has stored with different extension like 'photo.xyz' instead of 'photo.jpg or photo.png' using Picasso. to avoid image from gallery i am storing image like this. Please help me is there any option to show like this.
Neither Picasso nor Android (which does the actual image decoding) cares what the file name is. It can be anything. The type of the image is always determined from the first few bytes of the actual image data.
As a small workaround you can programmatically put .nomedia file into your app folder to prevent images to be cached by mediaserver and displayed in a Gallery app.
I am creating an app which i want to use to report field incidences at work.
Each incident may have one or more photos.
At this stage, i want to store the images locally on sd card and store their paths in the sqlite db.
So far i have figured out the db design and how to capture and save images on sd card and store their paths in the db.
What is challenging me now is how to dispay the images back?
I want a set up that dispalys the incident description and the associated image(s).
I have created xml file with textview to display the incident description and a gallery to dispaly images related to that incident.
My question is how to use image paths to create a gallery...or a better suggestion...
I have written code to retrieve incidences and related images ...
Ronald
Because when every app have some limitation regarding Heap allocation.... when u load images more than allocated heap space it will throw out of memory exception....
Use a Grid View or PageViewer to display a gallery. The one thing you have to do while using this is Memory management.
Note
This question is not aiming code answers. It intend to get some ideas
for best code practices that deals with the problem proposed.
Problem
List view that is connected as usual with array adapter of countries.
country object have 2 attributes. an image url and country name. at
the very first time images will be downloaded from the url and must be
saved on the internal memory. next time images will be loaded from the
internal memory if exist. otherwise, they will be downloaded.
What is the best structure to solve this problem?
Spot lights
a bitmap object is the container that a download steam will write to.
an image in the internal will also be sit to the bitmap object before we set bitmap to the image view.
(is this point optional) a bitmap ref. should be a member of the country class.
on download complete the downloaded image may and may not still needed because it's view is no longer visible (actually it is visible
but another country owns it). is it better to check that before we set
the image bitmap. or its better to just notify data changed.
What do you think?
Use this library for image downloading
https://github.com/nostra13/Android-Universal-Image-Loader
It has tons of features, you can cache in memory or on disk, has image loading events, and a ton of more stuff.
I have an app that have more than one gallery. It is a travel app and it have a separate gallery for each trip. When I'm taking pictures with the camera I'm saving them in the default MediaStore of the system.
To view an Image I'm using new Intent(Intent.ACTION_VIEW) and it launches the default image viewer. When scrolling with the left and right arrows it displays all the pictures in the folder where the pictures from the camera are saved.
Is there any way to put an extra in the intent when calling VIEW action which images to scroll trough? I have the IDs of the images for a certain trip in a database.
Or putting them in a separate folder is the only solution?
You could also consider building your own preview activity using a GridView. Of course this is more work to do, but also offers more flexibility:
You can create "virtual" folders
You can display images from local store or from the net (if you want to offer synchronization with web albums for example)
You can highlight certain images (favorite, shared)
I have several images present in different folders in my sdcard. I would like to display a list of thumbnails. So what I have done is while rendering any row in the list I read the file in an input stream, get the byte array, decode it to obtain a bitmap and set it in an imageview.
So far so good. But when I scroll the list, the list scrolls in jerks. I believe this is because decoding a bitmap from byte array takes some time. What I would like to know is that, is there any optimization which I can do to improve the performance, or better still is there any better method to achieve what I want ?
The better way in my opinion would be to add them to your resources folder as a drawable if you can. Then you can access them as a R.drawable system resource way faster.
ImageView iv;
iv.setBackgroundDrawable(getResources().getDrawable(R.drawable..));