Image transformation not applied after orientation change with Picasso - android

I am using Picasso and a RoundedTransformation class that applies rounded corners to an image I load with Picasso. Relevant code is below:
Transformation transformation = new RoundedTransformationBuilder()
.cornerRadiusDp(4)
.oval(false)
.build();
ImageView cardViewTop1Image = (ImageView) cardViewTop1.findViewById(R.id.cv_top1_image);
Picasso.with(cardViewTop1.getContext()).load("http:/some_image_url.com")
.fit().centerCrop()
.transform(transformation).into(cardViewTop1Image);
This all works great until I go through two orientation changes - first to horizontal orientation, then back to vertical orientation. When I switch back to vertical orientation, the rounded transformation is no longer applied.
I believe that Picasso is caching the non-transformed image and then filling the ImageView with it. Is there a way I could cache the transformed image or load the non-transformed image from the cache and then apply the transformation? Thanks for the help!

Try this approach to stop caching.
Picasso.with(yourContext)
.load(yourUrl)
.memoryPolicy(MemoryPolicy.NO_CACHE )
.networkPolicy(NetworkPolicy.NO_CACHE)
.fit()
.centerCrop()
.transform(yourTransformation)
.into(yourImageView);
Or try another Transformation. I use this https://gist.github.com/aprock/6213395 .

Related

Images are blurry when rotate the screen android device with Glide

I use glide to load the drawable image in the adapter (the error occurred with the image not located in recyclerview):
Glide.with (holder.ivPreview) .load (mThemeDrawableIds.get (position)).into (holder.ivPreview)
When recording mThemeDrawableIds will be reloaded and notify again. However, the image is blurred compared to the original image.
I tried clearing the cache but the result is still the same.
It might help to also add android:adjustViewBounds="true" to your ImageView in XML.
Also try this code :
Glide.with(imageView).load(mThemeDrawableIds.get (position))
.apply(new RequestOptions()
.fitCenter()
.format(DecodeFormat.PREFER_ARGB_8888)
.override(Target.SIZE_ORIGINAL))
.into(holder.ivPreview);

What is resize ,transformation of image in Picasso

I would like to know more details about what is transformation of image in Picasso what will happen if i use transformation for image in android and what is resize and transformation of image.
Picasso.resize(50, 50)
resizes the image to these dimensions (in pixel). does not respect aspect ratio
The transformations will give you enough tools to change the image according to your needs.

Is it possible to translate an ImageView on the android platform using Picasso?

For example, if I loaded an image into an ImageView as such:
Imeteor = (ImageView) findViewById(R.id.meteor1);
Picasso.with(this)
.load(R.drawable.red_meteor)
.resize((int) meteorWidth, (int) meteorHeight)
.into(Imeteor);
Is it then possible to translate (move across or around the screen) said ImageView using Picasso? The current method I am using is below.
Imeteor = (ImageView) findViewById(R.id.meteor1);
Imeteor.setX(meteorXPosition);
Imeteor.setY(meteorYPosition);
With the values of "meteorXPosition", and "meteorYPosition" being updated in a separate method from where the image is loaded. Also, "meteorXPosition", and "meteorYPosition" are updated every millisecond.
Or,
By the fact that the image is loaded using Picasso, does that mean that the every time the ImageView is accessed it is accessed through Picasso? For example, by the code I provided above
Imeteor = (ImageView) findViewById(R.id.meteor1);
Imeteor.setX(meteorXPosition);
Imeteor.setY(meteorYPosition);
For anyone who might read this, and doesn't bother to read the comments. Picasso only handles loading the bitmap, and performing transformations on the bitmap in the image view. For moving a bitmap within an image view an option is to use the image view's setX() and setY() function. Which moves the the image view to a new location (the bitmap is in the image view). For moving images it is best to look up how to move an image view.

Picasso center image without resizing into ImageView

I've come across this simple problem with the Picasso library. I haven't find any way to put an image into ImageView center it like android:ScaleType="center" does without cropping. Do you have any ideas about how to solve this ? My problem is that I don't know at the runtime the height and width of the BitMap I download so I can't use resize() properly.
This is a little late, but for anyone who's looking for a solution :
Picasso
.with(context)
.load(ImageURL)
.fit()
// call .centerInside() or .centerCrop() to avoid a stretched image
.into(imageViewFit);
If your ImageView is fixed one dimension and flexible another dimension (ex. android:width="match_parent", android:height="wrap_content"), you should be able to use android:adjustViewBounds="true" to get the ImageView to resize to display your image without cropping.
i am not found fit to center without resizing,
Picasso.get()
.load(source).resize(1650,700)
.centerCrop(Gravity.CENTER).into(imageView, new Callback()

Images are not clear - Picasso Android

I'm using Picasso for downloading images from URL and putting in ImageView. Images are rectangle, but my ImageViews are squares. So I need to use some cropping, because I have spaces on top and bottom.
Without cropping the image is clear:
Picasso.with(context)
.load(left.get(pos).getImageName())
.into(ivFrontPageLeftImage);
To fit inside and crop I'm using:
Picasso.with(context)
.load(left.get(pos)
.getImageName())
.fit().centerInside()
.into(ivFrontPageLeftImage);
But as you can see the image is not clear, it is blur.
So how can I fit image inside the square (ImageView). Also image need to be clear, not blur?
I download this image, crop it with size 300 x 300 (to be square, i cut from left and right) and upload it. I use this new image to put in ImageView:
Picasso.with(context)
.load("http://oi62.tinypic.com/29y61p3.jpg")
.fit().centerCrop()
.into(ivFrontPageLeftImage);
As you can see image is clear and it is not blur.
How can I do this programmatically? Is it possible with Picasso, or I need other library to do this?
I can't comment on Lee's answer as I don't have enough reputation. But his answer was correct as I had the same issue. You can also set it in the ImageView object by doing the following:
imageView = (ImageView) view.findViewById(R.id.img);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
Apply center crop on your ImageView instead of the method you are now using.
<ImageView
...
android:scaleType="centerCrop"/>

Categories

Resources