1
我正在从相机的图像上绘制覆盖图并将结果保存到文件中。为此,我传递一个包含以下代码的回调函数takePicture()。对于较大的图像尺寸,我在方法的第一行出现OutOfMemoryError崩溃。如何有效修改摄像头捕获的字节?
有什么办法可以更有效地做到这一点?看起来不可能从byte []制作一个可变的位图,这立即使我的内存使用率翻倍。如果在高分辨率下无法以这种方式完成,如何可以我在没有用完内存的情况下在大图像上生成覆盖图?
public void onPictureTaken(byte[] rawPlainImage, Camera camera) {
Bitmap plainImage = BitmapFactory.decodeByteArray(rawPlainImage, 0, rawPlainImage.length);
plainImage = plainImage.copy(plainImage.getConfig(), true);
Canvas combinedImage = new Canvas(plainImage);
combinedImage.drawBitmap(mOverlay, mOverlayTransformation, null);
//Write plainImage (now modified) out to a file
plainImage.recycle();
}