android中的createScaledBitmap位图超过32位错误

时间:2014-09-15 18:20:23

标签: android

调用以下方法时:

 Bitmap localBitmap = Bitmap.createScaledBitmap(paramBitmap, 360, (int)(360.0D / (paramBitmap.getWidth() / paramBitmap.getHeight())), false);

我将异常跟踪视为:

  

java.lang.IllegalArgumentException:位图大小超过32位

我使用语句打印了传入位图的大小:

  System.out.println("paramBitmap.getWidth() "+ paramBitmap.getWidth());
  System.out.println("paramBitmap.getHeight() "+ paramBitmap.getHeight());

,它是480x960

如何调试此问题并解决它。

1 个答案:

答案 0 :(得分:0)

我知道它的晚了但它可能对某人有所帮助,当我试图为位图绘制边框并将其旋转到某个角度时,我遇到了同样的问题,它总是在 xiaomi mi 移动中崩溃,我通过根据需要缩放位图来解决它,

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bmp = BitmapFactory.decodeFile(path, options);
final int BORDER_WIDTH = 10;
final int BORDER_COLOR = Color.YELLOW;
Bitmap res = Bitmap.createBitmap(bmp.getWidth() + 2 * BORDER_WIDTH,bmp.getHeight() + 2 * BORDER_WIDTH,bmp.getConfig());
Canvas c = new Canvas(res);
Paint p = new Paint();
p.setColor(BORDER_COLOR);
c.drawRect(0, 0, res.getWidth(), res.getHeight(), p);
p = new Paint(Paint.FILTER_BITMAP_FLAG);
c.drawBitmap(bmp, BORDER_WIDTH, BORDER_WIDTH, p);
float viewWidth = (float) res.getWidth();
float viewHeight = `enter code here`(float) res.getHeight();
float ratiowidth = vi`enter code here`ewWidth / (float) res.getWidth();
float ratioheight = viewHeight / (float) res.getHeight();
Matrix mat = new Matrix();
mat.postScale(ratiowidth, ratioheight);
mat.postRotate(45);
Bitmap bMapRotate = Bitmap.createBitmap(res, 0,0,res.getWidth(),res.getHeight(), mat, true);