Better way to resize images - android

I've been researching but I've not found anything good. Is there a way to resize images retrieved from a remote resource without the image losing quality? As for now, I do not have anything to resize my images. I just added android:scaleType="fitCenter" within my xml.

Have you tried Picasso? It's a powerful image loader, simple and easy to use. Below code is an example of how to use it.
Picasso.with(context)
.load(url)
.resize(width, height)
.centerCrop()
.into(imageView);

The only way for an image to be resized without losing quality are vectorized images.

Related

Benefits of .centerCrop()

I'm asking this question out of curiosity. Basically I'm using glide for loading images into imageView by setting the scaleType of image to centerCrop .But what I'm asking is Is it worth or good practice to use the glide's centercrop method instead of imageview's scaletype?.
I'm asking this because as far as I know glide will first download the image and then transform it into required shape .So, I don't think it will increase the downloading speed of image. Then where this method is useful?

Using high definition pictures in android

I'm having some trouble when uploading high definition pictures in my app.
I have a Grid View and when I add the photo the app crashes stating that its a memory problem.
One solution I did was to decrease the size of the image through a website (https://www.befunky.com/create/resize-image/) but the image gets blurie.
Also used a solution that is present on the official Android developers' website (https://developer.android.com/topic/performance/graphics/load-bitmap.html), unsuccessfully (the app gets too slow and I have the previous result).
I've seen many applications where this is not a issue and I want to learn the way they do it correctly.
Try Picasso, it can load an image into your imageView from your drawable (or url), and its fit() method allows you to reduce the image to the lowest possible resolution, without affecting quality.
Basically, it measures the dimensions of the target ImageView and uses resize() to reduce the image size to the dimensions of your ImageView:
High quality picture in drawable folder:
Picasso.with(context)
.load(R.drawable.image)
.fit()
.into(imageView);
High quality picture from a url:
Picasso.with(context)
.load("www.url.com/image.jpg")
.fit()
.into(imageView);
You can find more details on how to use fit, resizing and scaling with Picasso here.

Pixelated images on Picasso, not sure of the cause

We are using Picasso for image handling on our app and we have been having problems with pixelated images. Unfortunately I have been unable to figure out why this is happening, whether by trying out different combinations of things on Picasso, or trying to find the answer online.
Here is our code for image handling currently (some parameter names changed to be easier to read):
Picasso.with(image.getContext())
.load(imageUrl)
.resize(100, 125)
.centerCrop()
.placeholder(R.drawable.image1)
.error(R.drawable.image2)
.transform(new RoundedTransformation(10, 4))
.into(image)
The RoundedTransformation function just gives the images rounded corners and the code for it is here (we did not write this code): https://gist.github.com/aprock/6213395
centerCrop is necessary to prevent the images from being stretched out when they are put into the ImageView.
Does anyone know why pixelation of images might be happening? Thanks and have a great day.

Best method to resize network images in android for gridview

What is the best way to resize network images in android to show in android GridView. I've nearly 100 images to show in grid view. Each image is 1024*1024 resolution images. Kindly suggest the bet way to load these images into grid view with out getting out of memory error. Thanks in advance.
You can use Picasso for Image transformations.
http://square.github.io/picasso/
IMAGE TRANSFORMATIONS
Transform images to better fit into layouts and to reduce memory size.
Picasso.with(context)
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView)

loading image into android imageView with ion returns a blurry result

I'm trying to load an image from filesystem into an imageView with the ion library.
When I'm using the following code:
Ion.with(imageView)
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.load(uri);
it (sometimes) results in a kind of blurry image.
When not using ion like the following the pictures appear sharply:
imageView.setImageBitmap(BitmapFactory.decodeFile(uri.toString()));
Is there a standard compression coming with ion that I can disable?
Strangely not every picture is blurry when using ion, e.g. I have two identical images, only with another name. When I load them into the imageView with ion one is blurry, one is not.
Any help or tips are appreciated!
Ion tries to load the image to fit the bounds of the ImageView. So make sure your ImageView is sized properly in your layout. Alternatively, if you use adjustViewBounds=true to indicate the ImageView is adjusted by the image contents, it won't do that. Or alternatively smartsize(false).
Try this,
Ion.with(context)
.load(url)
.withBitmap()
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.intoImageView(imageView);

Categories

Resources