So I've got my image gallery project all set up with images saved online and not within the application. It works great. But what I want to do is get the facility to set the image as a wallpaper.
I've got the image to download and save in the external storage as packagename.jpg
Everywhere I've searched for examples on how to set the wallpaper all seem to be based on the image being within the application.
Anyone have any pointers on how to use wallpapermanger to set an image from external storage as the wallpaper?
You need to first retrieve the file from the SDCard and decode the image into a Bitmap using BitmapFactory then you can set the bitmap using WallpaperManager's setBitmap() method.
File file = new File(Environment.getExternalStorageDirectory(), "/directory/yourimage.jpg");
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getBaseContext());
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
wallpaperManager.setBitmap(myBitmap);
Related
I need to download images from server and store as thumbnails directly.
and for display images also i need to use images from .thumbnails folder directly. i am not getting how to create and save images as .thumbnail . and how to use images from that .thumbnail file.i searched online but everywhere only this below code present.
Bitmap thumb = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(file.getPath()), width, height);
any help?
Please check below code which helps you.
Follow below steps:
Calculate the maximum possible inSampleSize that still yields an image larger than your target.
Load the image using BitmapFactory.decodeFile(file, options), passing inSampleSize as an option.
Resize to the desired dimensions using Bitmap.createScaledBitmap().
Now you have your bitmap ready and you can save it any where using the following code
Bitmap thumbnail;
File thumbnailFile = ...;
FileOutputStream fos = new FileOutputStream(thumbnailFile);
thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, fos);
fos.flush();
fos.close();
hope it helps you and save your time.
Or use Glide library which store image as a full image and 1 thmbnail image which is power caching library which loads image quickly and once download image after load image from cache not from network.
Below is a Glide link please read it advantages and features and after used into your applications.
https://github.com/bumptech/glide
I've created a bitmap from canvas. Save it to my "/sdcard/folder/subfolder/file.png"
I want to get this png file into imageview after saving it. I tried this by using BitmapFactory.decodeFile("/sdcard/folder/subfolder/file.png"); method. But it returned nothing. There is no image on imageview.
Do you have any idea?
Try using
String filePath = Environment.getExternalStorageDirectory()+"/folder/subfolder/file.png";//or "folder/subfolder.."
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();
My Problem is I am getting Image from Gallery & use BitmapFactory.decodeResource() for Convert the image into bitmap but the Problem is the Image is get in Emulator but not in Real Device, In Real Device the Bitmap value is getting null. following is my code for decode Gallery Image.
String Galleryimagepath="/mnt/sdcard/DCIM/.thumbnails/1308059312410.jpg";
bmpImage = BitmapFactory.decodeFile(Galleryimagepath);
drawable = new BitmapDrawable(bmpImage);
mRlayoutmainimage.setBackgroundDrawable(drawable);
Any Help would be appreciated.
Yashwanth is right, the path may be different between device and emulator, further, the path may different device to device as well. You'd be better off getting a content URI for the image you want and using MediaStore.Images.Thumbnails.getThumbnail() to get the bitmap you're looking for.
MediaStore.Images.Thumbnails
I think sd card path on real device is different. you might have to use something like
Environment.getExternalStorageState()
check the following link.
Find an external SD card location
I want to retrieve an image from my data/data/com.apps.myapp/images folder and display it in an ImageView. Any clue?
Try this :
Bitmap bitmap = BitmapFactory.decodeFile("data/data/com.apps.myapp/images/img.png");
ImageView imgView = (ImageView) this.findViewById(R.id.imgViewId);
imgView.setImageBitmap(bitmap);
There are several components involved in this.
To get the path of your data folder you can use the method getDir in the Context.
Now you have to know the file name and open an stream here again the Context class is your friend. Now the stream can be decoded into a Bitmap via a Bitmap Factory.
After you got a Bitmap create a BitmapDrawable from it and pass it to your ImageView