Picasso does not return when processing a specific image.

Asked 2 years ago, Updated 2 years ago, 73 views

When I used the Android image processing library Picasso to process the image below, it was not returned (up to cycle) in the class implementing the following transformation, and this method looped? and eventually crashed with the image size and cut position values as follows.The original image size is 640 x 480.I don't know why it happens because it's made in other images.I would appreciate it if you could tell me the cause.I look forward to your kind cooperation.

Image URL
https://i.ytimg.com/vi/RFinNxS5KN4/sddefault.jpg

Where to Use Picasso

Picasso.with (mContext)
                    .load (APIUtil.checkThumbnail(item))
                    .transform(newViewUtils.TopThumbnailEditor())
                    .placeholder(R.drawable.top_thumbnail_placeholder)
                    .fit()
                    .into(holder.thumbnail);

Transformation Implementation Class

private static final float THUMBNAIL_HEIGHT_DIVINER=9f/16f;
private static final float TOP_HEIGHT_DIVINER = 16f/43f;

public static class TopThumbnailEditor implements Transformation {

        @ Override
        public Bitmap transform (Bitmap source) {
            float width = source.getWidth();
            float height = source.getHeight();

            float newHeight=width*THUMBNAIL_HEIGHT_DIVINER;
            floatheightCutSize=(height-newHeight)/2;
            newHeight=width*TOP_HEIGHT_DIVINER;
            float moreHeightCutSize = newHeight/2;

            Bitmap result=Bitmap.createBitmap(source,0,(int)(heightCutSize+moreHeightCutSize),(int)width,(int)newHeight);
            if(result!=source)
                source.recycle();
            return result;
        }

        @ Override
        public String key() {
            return "TopThumbnailEditor";
        }
    }

Final image size, cut position, etc.

 width: 1020.0
height —379.0
X coordinate cutting position: -97.375
Y coordinate cutting position: 189.76744

android

2022-09-30 20:51

1 Answers

Other images that work well are wide images, aren't they?

private static final float THUMBNAIL_HEIGHT_DIVINER=9f/16f;

I assume that the image that comes in in is 16:9, but it gives 4:3, so negative coordinates are created, and the latter stage becomes an error and loops.


2022-09-30 20:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.