Picasso - transformation bitmap quality - android

I am downloading low resolution pictures from web by using Picasso and displaying it in high res displays. Fetching images is straightforward:
Picasso.with(context)
.load(item.getPicture())
.transform(new BitmapTransformations.OverlayTransformation(
context.getResources(), R.drawable.ic_play_video))
.error(R.drawable.picture_placeholder)
.into(target);
Notice that I apply Overlay transformation into request - It's a high quality image asset I put on top of downloaded image. Applying overlay is also simple - just resize bitmap and put it in the center of image. But here comes the problem: Unless I add resizing, in my case:
.fit().centerCrop();
into Picasso request, overlaid high-res asset is copying quality of downloaded image (first picture). When I add this resizing before transformation the overlay looks as expected (second picture). Can anyone explain to me why this happens? Thanks you!

Related

Can Picasso crop an image without scaling?

I have an image that I'm trying to load with Picasso that I want to crop without scaling.
Is this possible?
For example, if I had:
an image that's 400x800
an image view that's 200x400
Any questions I've seen regarding cropping suggest using resize(x, y).centreCrop(alignGravity) (i.e. scaling and cropping rather than only cropping).
In the example, you'd get the entire image scaled to 50%, as the JavaDocs for centreCrop mentions:
This cropping technique scales the image so that it fills the requested bounds and then crops the extra, preferring the contents at alignGravity.
I want to display the middle 200x400 pixels of the image and lose the edges entirely (similar to how ImageMagick's crop would work).
Is there a way to crop without scaling?
So it seems that out-of-the-box, no it doesn't, but you can use the Picasso Transformations library to do so:
implementation 'jp.wasabeef:picasso-transformations:2.4.0'
and then:
Picasso.get()
.load(largeImage)
.transform(new CropTransformation(width, height, GravityVertical.CENTER, GravityVertical.CENTER))
.into(imageView, /* callback */);
If you are using resize() or centreCrop() you need to use after the call to transform().

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.

Picasso Not Downloading High Resolution Image

I have 3 URLs on gridview and only 2 of the 3 images load into the ImageView.
I am using Picaso:
Picasso.with(c).load(imageUrl).placeholder(R.drawable.progress_animation).fit().centerCrop().into(ivPicture);
I have also tried to skip caching:
Picasso.with(c).load(imageUrl).placeholder(R.drawable.progress_animation).fit().centerCrop().memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).into(ivPicture);
Additional Info of image:
Width 2048 / Height 1371 pixels
File size = 224KB
File format is JPG
When I use Picasso's .resize(h w)to a lower the resolution eg: resize (100 100) for testing the image is downloaded but the aspect ration is not kept as some images will have a 9:6 ratio or vice versa 6:9 or a perfect square 5:5 and therefore I do not want to resize any images to a fixed ratio instead I use .fit().centerCrop() which works very well except for this 1 high-res image, Picasso just loads on the placeholder endlessly without any errors, I can understand if the pixels are too many but the file size is quite small in size I don't know why Picasso is struggling to download a +/- 200KB image.
Is there a way for Picasso to compress images over certain pixels perhaps?
Picasso can not process very big images because will receive out of memory .You must to do image transformation inside native code .Not in java

Implementation for custom image cropping in Android

I need to implement the custom image cropping instead of using the system cropping (i.e. "com.android.camera.action.CROP"). I need to know the exact position of the cropping bounding box but this information is not retrievable if I choose to use the default cropping. Besides, the bitmap image is down sampled too much by default cropping.
The steps are as following:
Create the original size bitmap from source (using uri). The
original size is about 4000x3000 which is too big.
The user defines the crop area to extract the ROI which results in resizing of the original image to fit the ImageView. (size of ImageView is about 700x700)
Record the position of the bounding box in the ImageView.
Retrieve the cropped area from the original image and create another bitmap for it.
Resize the cropped bitmap to fit the imageview size to show it on the screen.
This approach works on my device (ZTE nuoio with Android 4.3) well. However, the app crashes on Samsung S4 with Android 4.4.4 and Note 4 while performing step 1 probably because of the out-of-memory error.
Therefore, I try to do another approach that creates the bitmap which is down sampled from the source image, rather than having the original size bitmap image.
I need to have the information of the exact position of cropped area from the original image. That is the reason why I didn't use default cropping. Could you please help me out with my case either providing
the solutions to derive the exact coordinates of the bounding box of the cropped image in the original image as a matrix.
how to solve the out-of-memory error in step 1 using the approach I mentioned above.
Or other approach to achieve image cropping with knowing the exact coordinates of cropped area form the original image.
Thank you so much.
For Crop an image and get Coordinates use library Edmodo Croper https://github.com/edmodo/cropper
For Out of memory issue you have to down scale image.

Is there a way to crop a large image on android without loading into memory?

I don't want to display the bitmap on the screen. Just trying to create a max square image out of the original image from sdcard and then uploading to server. Is there a way to crop an image without loading the image into memory? or load the image in chunks and then save to file?
I don't know if I understand well the question but this could help:
http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html
BitmapRegionDecoder can be used to decode a rectangle region from an image. BitmapRegionDecoder is particularly useful when an original image is large and you only need parts of the image.
Hope to help :)

Categories

Resources