Does ParseImageView cache ParseFile's in Android. If it caches parseFile, How can i find the path of those files in my android device.
ParseImageView imageView = (ParseImageView) findViewById(android.R.id.icon);
// The placeholder will be used before and during the fetch, to be replaced by the fetched image
// data.
imageView.setPlaceholder(getResources().getDrawable(R.drawable.placeholder));
imageView.setParseFile(file);
imageView.loadInBackground(new GetDataCallback() {
#Override
public void done(byte[] data, ParseException e) {
Log.i("ParseImageView",
"Fetched! Data length: " + data.length + ", or exception: " + e.getMessage());
}
});
Looks like #suresh kumar is dead right, so this question is settled with "no", but having run into this trouble I wanted to drop some code in here to get around it.
I use Universal Image Loader for URL image loading, and it supports a lot of configuration options for caching and display. Set it up in your Application class with (at time of writing):
//Create image options.
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.button_default)
.cacheInMemory(true)
.cacheOnDisc(true)
.build();
//Create a config with those options.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.defaultDisplayImageOptions(options)
.build();
ImageLoader.getInstance().init(config);
And then use it with Parse where you'd like to load and cache your image:
ParseImageView itemImage = (ParseImageView) v.findViewById(R.id.iv_item);
ParseFile photoFile = item.getParseFile("picture");
if (photoFile != null) {
//Get singleton instance of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance();
//Load the image from the url into the ImageView.
imageLoader.displayImage(photoFile.getUrl(), itemImage);
}
Hope that helps.
ParseImageView doesn't cache ParseFile, It is only used to display the image file stored in Parse.com. See this
and this
Related
I have used Universal Image Loader for load image from a server and also getting cached it into memory for fast loading.
But from server side used the same URL for update image.
For eg., www.example.com/xyz.png is URL for the image when they needed to update image they return same URL with a different image.
In this case, Universal Image Loader return image which is previously cached in memory (I think it cached image using its related URL).
So, I needed to Change image if URL returned a different image.
This is my code which I use for load image
DisplayImageOption.java
public class DisplayImageOption {
public static DisplayImageOptions getDisplayImage() {
// .displayer(new RoundedBitmapDisplayer(0))
return new DisplayImageOptions.Builder()
.showImageOnLoading(R.mipmap.icon_place_holder)
.showImageForEmptyUri(R.mipmap.icon_place_holder)
.showImageOnFail(R.mipmap.icon_place_holder)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true).build();
}
public static DisplayImageOptions getDisplayRoundedImage() {
return new DisplayImageOptions.Builder()
.showImageOnLoading(R.mipmap.icon_place_holder)
.showImageForEmptyUri(R.mipmap.icon_place_holder)
.showImageOnFail(R.mipmap.icon_place_holder)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.displayer(new RoundedBitmapDisplayer(100)).build();
}
}
Code for Image Loading
ImageLoader.getInstance().displayImage(url, imageView, DisplayImageOption.getDisplayImage());
Thanks
In your ImageLoaderConfiguration add diskCache option.
File cacheDir = StorageUtils.getCacheDirectory(context);
long cacheAge = 10L;
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.diskCache(new LimitedAgeDiscCache(cacheDir, cacheAge)) // this will make the cache to remain for 10 seconds only
.build();
Then set it on ImageLoader and display image with your DisplayImageOption
ImageLoader.getInstance().init(config);
ImageLoader.getInstance().displayImage(url, imageView, DisplayImageOption.getDisplayImage());
What it does?
Taken from Android-Universal-Image-Loader
LimitedAgeDiscCache (Size-unlimited cache with limited files' lifetime. If age of cached file exceeds defined limit then it will be deleted from cache.)
And this piece of code is from Android-Universal-Image-Loader's LimitedAgeDiskCache.java class.
/**
* #param cacheDir Directory for file caching
* #param maxAge Max file age (in seconds). If file age will exceed this value then it'll be removed on next
* treatment (and therefore be reloaded).
*/
public LimitedAgeDiskCache(File cacheDir, long maxAge) {
this(cacheDir, null, DefaultConfigurationFactory.createFileNameGenerator(), maxAge);
}
You may like this approach as well.
I am successfully integrate Universal Imageloader in my Gallery App to show the images from the phone storage
But new images (captured from the camera /processed images) stored in the app's specified folder doesn't appear in the gallery. even the application restarted.
May be due to this error
W/ImageLoader: Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.
I think add the details of new image to the cache will resolve the problem. but don't know how . please help
code : Activity Extends Application
DisplayImageOptions defaultDisplayImageOptions = new DisplayImageOptions.Builder() //
.considerExifParams(true)
.resetViewBeforeLoading(true)
.showImageOnLoading(R.drawable.nophotos)
.showImageOnFail(R.drawable.nophotos)
.delayBeforeLoading(0)
.build(); //
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.defaultDisplayImageOptions(defaultDisplayImageOptions)
.memoryCacheExtraOptions(480, 800).threadPoolSize(5)
.build();
ImageLoader.getInstance().init(config);
load all album
PhoneMediaControl mediaControl = new PhoneMediaControl();
mediaControl.setLoadalbumphoto(new loadAlbumPhoto() {
#Override
public void loadPhoto(ArrayList<AlbumEntry> albumsSorted_) {
albumsSorted = new ArrayList<PhoneMediaControl.AlbumEntry>(albumsSorted_);
if (mView != null && mView.getEmptyView() == null) {
mView.setEmptyView(null);
}
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
});
mediaControl.loadGalleryPhotosAlbums(mContext, 0);
is there any way to add new processed image to the cache or already initiated imageloader
You just have to load the your image with universal image loader it will automatically cache it.
Loading
ImageLoader imageLoader = ImageLoader.getInstance();
Uri uri = Uri.fromFile(new File("/DCIM/Camera/1470634175974.jpg"));
imageLoader.loadImage(uri.toString(), new SimpleImageLoadingListener() {
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
}
});
UNIVERSAL IMAGE LOADER ACCEPTED URI schemes
"file:///mnt/sdcard/image.png" // from SD card
"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
"content://media/external/images/media/13" // from content provider
"content://media/external/video/media/13" // from content provider (video thumbnail)
"assets://image.png" // from assets
"drawable://" + R.drawable.img // from drawables (non-9patch images)
Initialize your UniversalImageLoader instance only once inside onCreate() of your Application class, not inside each Activity or elsewhere.
I found this will reslove the problem using the function loadImageSync();
ImageLoader.getInstance().loadImageSync(filepath);
Use two biblotecas in my application, Universal Image Loader and another that uses the library picasso,
the picasso library, records the image in the cache /cache/picasso-cache/ and the names are generated with the MD5 URL.
To separate the cache Universal Image Loader, I write to /cache/LazyLoad/ and names generated with the item ID.
My code of configuration Universal Image Loader
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.resetViewBeforeLoading(true)
.cacheOnDisk(true)
.cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.displayer(new FadeInBitmapDisplayer(300))
.build();
ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(getApplicationContext());
config.defaultDisplayImageOptions(defaultOptions);
config.memoryCache(new WeakMemoryCache());
config.threadPriority(Thread.NORM_PRIORITY - 2);
config.denyCacheImageMultipleSizesInMemory();
config.tasksProcessingOrder(QueueProcessingType.LIFO);
config.writeDebugLogs(); // for debug
FileNameGenerator fileNameGenerator = new FileNameGenerator() {
#Override
public String generate(String imageUri) {
String fileName = imageUri.substring(imageUri.lastIndexOf('/')+1, imageUri.length());
String fileNameWithoutExtension = fileName.substring(0, fileName.lastIndexOf('.'));
return fileNameWithoutExtension;
}
};
String pathCache = Globais.getCacheDirImageLazyLoad(mContext); //returns StorageUtils.getCacheDirectory(context, false).getAbsolutePath() + "/lazyload";
File f = new File(pathCache);
if (!f.exists())
f.mkdirs();
DiskCache diskCache = new UnlimitedDiskCache(f, null, fileNameGenerator);
config.diskCache(diskCache);
config.diskCacheFileNameGenerator(fileNameGenerator);
ImageLoader.getInstance().init(config.build());
Problem that after I started using the component that uses the picasso, began to double the cache, ALL images that use the Universal Image Loader, also appear in Picasso's cache.
How can I fix this ???
Anyone have any idea?
I have gone through many questions similar to mine of images flickering problem.
I am not able to correct it. Being a beginner,I am not able to understand what to do.
Here is my code.. where I set thumbnail for a image.
private void setThumbnail(final ContentResolver contentResolver, final ViewHolder aHolder,
final Uri uri) {
new AsyncTask<String, Void, Bitmap>() {
#Override
protected Bitmap doInBackground(String... params) {
Bitmap result = mBitmapCache.get(uri.toString());
if (result == null)
return getThumbnail(contentResolver, uri);
else
return result;
}
#Override
protected void onPostExecute(Bitmap result) {
if (uri != null && result != null) {
// Log.d(TAG, "setThumbnail result not null");
// Log.d(TAG, "uri= "+uri);
// Log.d(TAG, "aHolder.mMediaUri= "+aHolder.mMediaUri);
mBitmapCache.put(uri.toString(), result);
// confirm the holder is still paired to this uri
if (!uri.equals(aHolder.mMediaUri)) {
return;
}
// set the thumbnail
ImageLoader imageLoader=ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(getContext()));
DisplayImageOptions options = new DisplayImageOptions.Builder()
// .showImageForEmptyUri(R.drawable.ic_empty)
// .showImageOnFail(R.drawable.ic_error)
.resetViewBeforeLoading(true).cacheOnDisk(true)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565).considerExifParams(true)
.cacheInMemory(true)
.displayer(new FadeInBitmapDisplayer(300)).build();
imageLoader.displayImage(uri.toString(), aHolder.mMediaThumbnail, options);
// aHolder.mMediaThumbnail.setImageBitmap(result);
} else {
// Log.d(TAG, "setThumbnail result null");
}
}
}.execute();
}
In ListView view is added when it is required (See https://stackoverflow.com/a/14108676/2274724). So your item will create when you call notifyDataSetChange() or scroll your list.
So whenever your view is created your image will load again from cache which results into flickering. There is a solution :
First Load image in background thread (Either from network or assets) then create a bitmap cache as u did but instead of getting image using AsyncTask get Image directly if it exist in bitmap cache (But this is again not a good way because it will stop flickering but list scroll will not be smooth when size is large).
I will Suggest use UniversalImageLoader. They implemented memory cache in much better way.
private void setThumbnail(final ContentResolver contentResolver, final ViewHolder aHolder,
final Uri uri) {
ImageLoader.getInstance().displayImage(
uri.toString(),
aHolder.mMediaThumbnail, getDisplayOption());
}
// Add or remove option according to your requirement
private DisplayImageOptions getDisplayOption() {
return new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_launcher)
.showImageOnLoading(R.drawable.ic_launcher)
.showImageOnFail(R.drawable.ic_launcher).cacheInMemory(true)
.cacheOnDisk(true).resetViewBeforeLoading(true)
.displayer(new RoundedBitmapDisplayer(22))
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(Bitmap.Config.RGB_565).build();
}
//Put it in your Application file and call it just once.
private void initImageLoader() {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.diskCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.defaultDisplayImageOptions(getDisplayOption()).build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
}
Before I was using:
AssetManager
InputStream
BitmapFactory
All of this to get a Bitmap
And finally use imageView.setImageBitmap(bitmap)
Nowadays we have libraries that help loading and caching images.
I have used Picasso for loading images from the web.
But Picasso is available for assets too!
Here is a Kotlin example:
val picassoPrefix = "file:///android_asset"
Picasso.get().load("$picassoPrefix/$assetsPath/$fileName")
.placeholder(R.mipmap.ic_launcher_round)
.into(imageView)
Note:
We can use the fetch method for preloading too.
In my case I don't think it's necessary, since the placeholder is displayed for the first time, and for the next times, the images are displayed immediately without flickering.
I do exactly what this guy suggests which is exactly the same as the creator of the Universal Image Loader, but I still get this error:
URI = assets://NMF0002_007.jpg
resolveUri failed on bad bitmap uri: NMF0002_007.jpg
What should I look for to ensure that the images are recognised?
I use it like this:
//get the file name
String fileName = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseHelper.FIELD_RESOURCE));
String imageUri = "assets://";
Log.d(TAG, "URI = " + imageUri + fileName);
ImageLoader.getInstance().displayImage(imageUri+fileName, holder.iv_details_resource);
This is my configuration:
//Get the imageloader.
ImageLoader imageLoader = ImageLoader.getInstance();
//Create image options.
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheOnDisc()
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
//Create a config with those options.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.defaultDisplayImageOptions(options)
.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75)
.build();
//Initialise the imageloader.
imageLoader.init(config);
What am I doing wrong or missing?
Solution - I was looking for .jpg and my file extension was .JPG
If NOSTRA can post some clever things to be on the lookout for I'll mark your answer as an official answer to my silliness.