Loading Image orientation wrong - android

Hi I used the picasso library for load the image from server url. But some of images loading in wrong orientation. ExifInterface is class to find out the image orientation but here image is not in resource folder. I have only image url but i want to show the image in correct orientation. How I can achieve to show the image on imageview with correct view.
Picasso.with(context)
.load(url)
.resize(200, 200)
.centerCrop()
.placeholder(R.drawable.ic_pic)
.error(R.drawable.ic_pic)
.into(holder.image);

Related

Glide and image resolution

I'm loading an image from a file. It's a photo gallery so I don't want the image resolution to be scaled down. I've found this code snippet that seems to work great on my devices but I've had users complain about low res images before (That I've been unable to replicate but have confirmed they're real issues) so I want to play it safe.
Will this code snippet load the full resolution image or does it require more than this?
File pageFile = getPageFile();
Glide.with(mPhotoView).load(pageFile)
.apply(new RequestOptions()
.override(Target.SIZE_ORIGINAL))
.into(mPhotoView);
For clarity:
Previously, we were creating our own bitmap from the file input stream and applying it like this:
Glide.with(mPhotoView).load(bitmap).into(mImageView);
This is when users started complaining about image resolution
Please try below:-
Glide.with(imageView).load(url)
.apply(new RequestOptions()
.fitCenter()
.format(DecodeFormat.PREFER_ARGB_8888)
.override(Target.SIZE_ORIGINAL))
.into(imageView);
Also, add this android:adjustViewBounds="true" to your ImageView in XML.
You can use centerCrop() instead of fitCenter() to scale. If used centerCrop(), it scales the image so that it fills the requested bounds and then crops the extra.

jpeg image format not supported by picasso or glide

Picasso and Glide aren't supporting/loading image URL with .jpeg extension within image view.
I am working in grid view where image is being loaded in image view , either by picasso or by glide but it isn't supporting the URL with .jpeg extension.
Are there any alternates available?
Glide.with(getActivity())
.load("https://abc/profile.jpeg")
.centerCrop()
.placeholder(logo)
.into(imageView);
Picasso.get()
.load("https://abc/profile.jpeg")
.placeholder(R.drawable.logo)
.error(R.drawable.logo)
.into(imageView);
Change the extension of images to .jpg and it'll work.

Loading image in android imageview

How to load images in same image view from web or local android gallery?
I have an image view which has three options for loading images templates from web service,from gallery, from camera.I am using Glide library to load images from web service, Now, if i load image from web by glide and remove that image by remove button which i have for removing a picture after i pick image from gallery it doesn't load the image from gallery instead load the same image from glide which i removed before.
write the code like this for loading image .
Glide.with(mContext).load(imgUrl)
.thumbnail(0.5f)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
Glide Library Intoduction Go through with this link, hope it will be work
You can use Picasso library. Image loading using Picasso is very easy, you can do it like this way
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
and in their website you can get every details.
and another Library is Glide. You can use Glide too for loading image..
You can also use Glide:
Glide.with(context).load(image).asBitmap().placeholder(R.drawable.placeholder).error(R.drawable.error).into(imageview);

Android Glide: Show a blurred image before loading actual image

I am developing an Android app which displays full screen images to the user. Images are fetched from the server. I am using Glide to show the image. But I want to display a very small size blurred image before displaying the actual image. Once the image is cached, directly full sized image should be shown.
Image Displaying flows goes like this:
- If image is downloaded for the first time, first download a small scaled image, and then download full resolution image.
- If image has been downloaded before, directly show full scale image.
I cannot find any method in Glide library, which tell me if a file exist in cache or not.
Any idea, how this can be done.
Glide.with(context.getApplicationContext())
.load(Your Path) //passing your url to load image.
.override(18, 18) //just set override like this
.error(R.drawable.placeholder)
.listener(glide_callback)
.animate(R.anim.rotate_backward)
.centerCrop()
.into(image.score);
with Glide v4:
Glide.with(context)
.load(URL)
.thumbnail(0.1f)
.into(image_view)
Better you can get idea from this Library or Use this library.
2 ways to do Blur and Original image in Android.
1) Initially load Blur Image Server URL path and once get success bitmap caching mechanism to load Original(Large) Image Server URL path.
Point 1 is possible, I got answer for you( Ask your server team to get Blur image or Low quality image to make blur and then load large image).
APK Link
Glide.with(mContext)
.load(image.getMedium())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
// Do something with bitmap here.
holder.thumbnail.setImageBitmap(bitmap);
Log.e("GalleryAdapter","Glide getMedium ");
Glide.with(mContext)
.load(image.getLarge())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(new SimpleTarget<Bitmap>() {
#Override
public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
// Do something with bitmap here.
holder.thumbnail.setImageBitmap(bitmap);
Log.e("GalleryAdapter","Glide getLarge ");
}
});
}
});
2) Fresco by Facebook is a new image library for Android. Here’s the official blog post introducing the library. It supports the streaming of progressive JPEG images over the network which can be really helpful to display large images over slow connections. One can see the image gradually improve in quality.
Progressive JPEGs with Facebook Fresco
Use BitmapFactory.Options.inSampleSize to make a downsampled version of the image, and upload both versions. Load the sample image (which should take less time) and when the bigger version is downloaded, switch to that. You could also use a TransitionDrawable to make a fade transition.
this is not a perfect way but it will be easiest way to make it.
make placeHolder image as blur and set it into glide. then always it will show blur image and then after load the actual image it will appear.
you can refer this code to use glide.
//crete this method into your Utils class and call this method wherever you want to use.
//you can set these placeHolder() and error() image static as well. I made it as comment inside this method, then no need to use [placeHolderUrl and errorImageUrl] parameters. remove it from this method.
public static void loadImage(final Activity context, ImageView imageView, String url, int placeHolderUrl, int errorImageUrl) {
if (context == null || context.isDestroyed()) return;
//placeHolderUrl=R.drawable.ic_user;
//errorImageUrl=R.drawable.ic_error;
Glide.with(context) //passing context
.load(getFullUrl(url)) //passing your url to load image.
.placeholder(placeHolderUrl) //this would be your default image (like default profile or logo etc). it would be loaded at initial time and it will replace with your loaded image once glide successfully load image using url.
.error(errorImageUrl)//in case of any glide exception or not able to download then this image will be appear . if you won't mention this error() then nothing to worry placeHolder image would be remain as it is.
.diskCacheStrategy(DiskCacheStrategy.ALL) //using to load into cache then second time it will load fast.
.animate(R.anim.fade_in) // when image (url) will be loaded by glide then this face in animation help to replace url image in the place of placeHolder (default) image.
.fitCenter()//this method help to fit image into center of your ImageView
.into(imageView); //pass imageView reference to appear the image.
}
glide has a direct way of doing this :
val thumbnailRequest = Glide.with(this)
.load("https://picsum.photos/50/50?image=0")
Glide.with(this)
.load("https://picsum.photos/2000/2000?image=0")
.thumbnail(thumbnailRequest)
.into(imageThumbnail)
from the blog:
Thumbnails are a dynamic placeholders, that can be loaded from the Internet. Fetched thumbnail will be displayed until the actual request is loaded and processed. If the thumbnail for some reason arrives after the original image, it will be dismissed.
You must have a small-size and a full-size image on your server. You can use Firebase Resize Image Extension if you are using Firebase as your backend. Once you have a small-size image URL and a full-size image URL you can use Glide like this:
Glide.with(context)
.load(fullSizeImageUrl)
.thumbnail(
Glide.with(context)
.load(smallSizeImageUrl)
).into(imageView)
You'll get that blurry effect as the small-size image will be blurry
According to Glide Doc:
.thumbnail()
loads and displays the resource retrieved by the given thumbnail request if it finishes before this request. Best used for loading thumbnail resources that are smaller and will be loaded more quickly than the full size resource. There are no guarantees about the order in which the requests will actually finish. However, if the thumb request completes after the full request, the thumb resource will never replace the full resource.
use BitmapFactory.Options.inSamleSize to load a downsampled version of the image. Then load the bigger image and do a fade transition using a TransitionDrawable
Hope this will Helps you ! Cheers !

Android Glide click on item Gridview show image full screen

I'm using Glide to download and display images in my gridview. When I click on a item in my gridview I want to display this image in another activity to get this image in full screen. But with Glide I don't know how I can get the image saved in the cache.
Save the image filename in a Database and call again the link to download the image full size with Glide ?
Or try to get the image in the cache but I don't know how to do that.
Could you help me ?
try this code, it's working for me:
On your adapter:
Glide.with(context)
.load("photo_url")
.diskCacheStrategy(DiskCacheStrategy.ALL) //use this to cache
.centerCrop()
.crossFade()
.into(yourImageView);
On your another Activity:
Glide.with(AnotherActivity.this)
.load("photo_url")
.diskCacheStrategy(DiskCacheStrategy.ALL) //use this to cache
.crossFade()
.into(yourImageView);
Use .diskCacheStrategy(DiskCacheStrategy.ALL) to cache & don't forget to make image scaling same. It will working.

Categories

Resources