Adding Images to Drawable Folder from a Server - android

I need to add images into res/drawable folder dynamically as the user select images of his choice from a server...then store the corresponding R.drawable.imageid to Database..so as to load the user chosen images on the next run...Is there no way to do so...?
int[] images = {
R.drawable.m1,R.drawable.m2, R.drawable.m3,
R.drawable.m4,R.drawable.m5, R.drawable.m6,
R.drawable.m7, R.drawable.m8,
R.drawable.m9
};
ImageView iv = (ImageView)findViewById(imageViews[next]);
iv.setImageResource(images[j]);
Here R.drawable.m1, R.drawable.m2, R.drawable.m3, R.drawable.m4, R.drawable.m5, R.drawable.m6, R.drawable.m7, R.drawable.m8, R.drawable.m9 should be ids of images chosen by user from the server

Quoting Android Engineer RomainGuy
You cannot write to res/drawable.
However you can look for other alternatives like external storage.
Links to consider are
android image save to res/drawable folder
How to convert a Drawable to a Bitmap?
Android: Image save to location

u cannot copy the images in drawable folder.
create folder in data folder and write images there and use bitmap class to map the image.

Related

Load the images from the Gallery into gridview

This LazyLoading library helps me to load the images from the internet. Can i use this library to load the images from the gallery.
imageLoader.DisplayImage(url, image);
What should i send the argurment to display the image from the gallery
Note I'm having the path of the images in the ArrayList
Imp Note : I'm also having the ArrayList of byteArray (one byte array resembles to one image). So then how can i use the library
Edit I encrypted some images from the gallery and stored in SDCard and i need to display the encrypted images in my app(I know the path of the encrypted images) Encryption is done in Byte[] level.
Please suggest me. ThankYou
Can i use this library to load the images from the gallery?
Gallery itself a application which is showing images from your local folder. So if you have a local image you can show it by its path in your App.
You just need to add file in your image path to make path as URI.
Like
String URL = "file:///mnt/sdcard/image.png"; // from SD card

How to use Universal image Loader for loading resources locally

I want to know how can i use nostra13 / Android-Universal-Image-Loader for displaying Images locally i.e from drawable folder along with the Memorycache. I want to use it with ViewPager.
any help will be greatly appreciated.
To load images from assets and drawables you should take ExtendedImageDownloader from example project (this class is not a part of library yet) and also set it to configuration.
UPD: Loading local resources (from drawable, assets, content provider) works out of the box since UIL v1.8.0.
See README:
String imageUri = "assets://image.png"; // from assets
String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)
NOTE: Use drawable:// only if you really need it! Always consider the native way to load drawables — ImageView.setImageResource(...) instead of using of ImageLoader.
Whenever More than one image load from resource dynamically (#runtime) than prefer these one:
String imgUri = "drawable://" + getResources().getIdentifier(imgName, "drawable", getActivity().getPackageName());
Here, imgName = Name of image in resource

Save image to sdcard from imageview

I have listview having customized some textview and one imageview. When I long click on item I have store that item information to the database but the question is how to store image in sdcard and store the relevant path to the database. The image alread download as cache now I don't want to re-download that image.
Is there way to store that Image to the sdcard.
I am using this example to download the images for listview https://github.com/thest1/LazyList
Edit
I got solution
no need to extra process when using this example. Just store the web path of image into the database and pass that imageview into the ImageLoader object with path it'll use the cache images if the image was exist for same URL
No Need to extra process, Using this example it'll will care for future usage also for same URL of image. This will get from the cache directory if the image found that use that image otherwise download it and then use it.
If you use Prime the caching will be transparent, when you request the image again it will grab it from a memory cache if available or a disk cache automatically. It also is really easy to get images with.
You can save your bitmap which you get via Bitmap bitmap=memoryCache.get(url); using save-file-to-sd-card.
You can also get the bitmap from the ImageView(if you want) like:
//say your ImageView object is i;
i = (ImageView) findViewById(R.id.img);
Drawable d = i.getBackground();
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

How to get the ID of images which are stored in smart phone's library

from the beginning I use
Drawable pic = getResources().getDrawable(R.drawable.android);
to get the drawable object while R.drawable.android means the ID of the picture I put in drawable folder.
However, I would like to get also the drawable object of the images which are stored in library.
do you have any suggestion
I hope you mean by stored in library mean some where in SD card, then use
Drawable pic = Drawable.createFromPath(pathName);
or to get from stream
Drawable pic = Drawable.createFromStream(is, srcName)

Accessing an image outside the drawable folder in android

I have been using the images in the drawable folder to display images In my Android Application. Is there any way to access the images outside the drawable folder? Or images in another through a url?
The BitmapFactory class has different methods allowing you to decode resources from streams or files, you should check it out.
Just use PackageManager:
getDrawable (String packageName, int resid, ApplicationInfo appInfo)

Categories

Resources