Save image in SD card after picasso load image - java

I am using picasso plugin to load image.
Picasso.with(context).load(BackendConfig.media_url+folder+holder.media_name).resize(150, 150).into(holder.imageView);
It's working fine. But, I want to save that image in SD card by loading just once from URL.
How can I do that?

Picasso using LRU disk cache, no need to worry about loading it from URL once. If you need to load and save actual image as file, load it as bitmap resource instead, and use Bitmap.compress and FileOutputStream to save into file (PNG/JPEG/WEBP).

you can use this lightweight android library VINCI (wrot this for my self) its do every thing you want
caching - using LruCache
managing files/bitmaps (Saving files in internalStorage)
read this WIKI part for more visit my github repo .
Storage store = Vinci.base(context).process().load(uri).file();
Log.e("Created", Boolean.toString(store.isCreated()));
Log.e("FileObject", store.FileObject().toString());
Log.e("FullPath", store.getfullPath().getPath());
Log.e("LocalPath", store.LocalPath());
Log.e("Get Bitmap File", String.valueOf(store.getBitmap()));

Related

How to add src path image to my pdf using Image.getInstance() method?

Here in my web-application under Images folder pdficon.png image is available I want to add this image using Image.getInstance() method but whaen I tring like this..
image = Image.getInstance("images/pdficon.png");
Here it showing Exception is
IOException :: C:\Users\Developpc\Downloads\wildfly-9.0.2.Final\bin\images\pdficon.png (The system cannot find the path specified)
So,what I need to do....
Signup for some free image hosting account and upload your image. After uploading your image you can get the URL of the image and put that URL for image.getInstanceMethod.
Image img = Image.getInstance(IMG_URL);
If you are using that image multiple times then create an string constant and use that.

using glide with iocipher

I am using glide in order to set images in my GridView, and I am using a library named IOcipher which provides a virtual encrypted disk, so I use info.guardianproject.iocipher.File instead of java.io.file . But glide can't load images, and it has a error saying :
E/Glide: class com.bumptech.glide.load.engine.GlideException: Failed
to load resource
is there any way I could load images? I tried many different ways :(
file.getPath() returns /data/user/0/com.example.zeinab.amndoorbin/app_vfs/myfiles.db/1502685968291.jpg
Glide.with(mContext)
.load(file.getPath()) // Uri of the picture
.into(imageView);

Notify images ContentProvider about new file on external storage

How should I notify images Content Provider, that I just saved a file in Pictures directory? I expect e.g. Gallery-like apps to be able to see my new file.
Uri uri = Uri.fromFile(file);
getContext().getContentResolver().notifyChange(uri, null);
which I found somewhere (Vogella?) does not seem to work. Or is it a wrong approach from the start?
The image notification is done after the image is inserted into media database. This is usually done by the android system media scanner when it finds the image.
You can write your own code to insert the image into the media database and then call getContext().getContentResolver().notifyChange(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null); to notify that some image has changed without beeing specific exatly which image.
If you modified an image that is already in the media database you have to translate the file uri into a content: uri. getContext().getContentResolver().notifyChange(imageContentUri, null); .
If you are implementing for android-4.4 or later You can ask the media scanner to (re)analyse your file. For details see How to trigger MediaScan on Nexus 7? . in pre android-4.4 this might not work as expected (i.e. on my android-4.2 it starts a complete rescan)

How to effectively load url remote image in ViewPager?

Usually we loading picture is on FragmentPagerAdapter.getItem method.
such as:
Picasso.with(context)
.load(url)
.placeholder(R.drawable.user_placeholder)
.error(R.drawable.user_placeholder_error).into(imageView);
Images then don't show in ViewPager probably never download. But, I want to pre-download images. I've used Picasso.with().load(url).downloadOnly, but this causes multiple unnecessary same url downloading.
I want to pre-download images. If have same url image downloading, it merge downloading interface.
I'm using Glide.It's effective and power.Preload image only use preload() method.

Caching Zoomable Web Image

Aquery
Zoomable Web Image
In addition to ImageView, a WebView can be used to display an image along with Android build in zoom support for WebView. Image will be centered and fill the width or height of the webview depending on it's orientation.
I using,
String url1 = "file:///mnt/sdcard/image.jpg";
aq.id(R.id.webView1).progress(R.id.progress).webImage(url1);
I noticed that even if I cut off the connection and re-open that application, the image is still displayed. Is it cached? I looked into its sd card folder, nothing there. I'd like to utilize cached images instead of fetching it many times.
Also, I am both using Universal-Image-Loader and Android Query. I am just concern if they can both read cached images.
//Aquery
//returns the cached file by url, returns null if url is not cached
File file = aq.getCachedFile(url);
The url1 is being downloaded every time you call
aq.id(R.id.webView1).progress(R.id.progress).webImage(url1);
Your cached file is being returned to File file object but you arent making use of it in

Categories

Resources