Rotating images on android. Is there a better way?

后端 未结 3 1029
-上瘾入骨i
-上瘾入骨i 2020-12-31 13:48

I have an app that displays quite a few images for the user, and we\'ve been seeing a lot of error reports with OutOfMemoryError exception.

What we curr

3条回答
  •  情歌与酒
    2020-12-31 14:23

    you can try:

    image.setImageBitmap(null);
    // Check if image is a landscape image
    if (bmp.getWidth() > bmp.getHeight()) {
        // Rotate it to show as a landscape
        Matrix m = image.getImageMatrix();
        m.postRotate(90);
        bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
    }
    BitmapDrawable bd = new BitmapDrawable(mContext.getResources(), bmp);
    bmp.recycle();
    bmp = null;
    setImageDrawable(bd);
    bd = null;
    

提交回复
热议问题