我正在从画廊拍摄图像并进行压缩。在我得到的代码片段中无法压缩recyled位图错误。,仅在少数设备上。我也尝试更改代码,但它的发生只是非常罕见的情况。无法找到解决方案,请参阅我的方法
public byte[] getByteArrayOfImage(int position) {
byte[] bytes = null;
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Bitmap loadedImage = this.images.get(position);
try {
float imgWidth = (float) loadedImage.getWidth();
float imgHeight = (float) loadedImage.getHeight();
if (imgWidth > MAX_IMAGE_WIDTH) {
float scaleFactor = imgWidth / MAX_IMAGE_WIDTH;
loadedImage = Bitmap.createScaledBitmap(loadedImage, (int) (imgWidth / scaleFactor), (int) (imgHeight / scaleFactor), false);
}
loadedImage.compress(Bitmap.CompressFormat.JPEG, Constants.SCALE_IMAGE, byteArrayOutputStream);
bytes = byteArrayOutputStream.toByteArray();
} finally {
try {
byteArrayOutputStream.flush();
byteArrayOutputStream.close();
Helper.getInstance(mContext).recycleBitmap(loadedImage);// Recycling the bitmap image.
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
}
return bytes;
}
此行
loadedImage = Bitmap.createScaledBitmap(
出现错误,请告诉我需要完成的建议。