Resize a large bitmap file to scaled output file on Android

前端 未结 21 1437
执念已碎
执念已碎 2020-11-22 05:51

I have a large bitmap (say 3888x2592) in a file. Now, I want to resize that bitmap to 800x533 and save it to another file. I normally would scale the bitmap by calling

21条回答
  •  暖寄归人
    2020-11-22 06:23

    No. I'd love for someone to correct me, but I accepted the load/resize approach you tried as a compromise.

    Here are the steps for anyone browsing:

    1. Calculate the maximum possible inSampleSize that still yields an image larger than your target.
    2. Load the image using BitmapFactory.decodeFile(file, options), passing inSampleSize as an option.
    3. Resize to the desired dimensions using Bitmap.createScaledBitmap().

提交回复
热议问题