我试图从我的 android 应用程序在 Facebook 墙上发布图像。为此,我从布局创建了一个位图。这是我的代码
System.gc();
Bitmap bitmap = Bitmap.createBitmap(
view.getMeasuredWidth(),
view.getMeasuredHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Drawable bgDrawable = newLinearLayout.getBackground();
if (bgDrawable != null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(1.0f, 1.0f);
// recreate the new Bitmap
Bitmap resizedBitmap = null;
resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
//Canvas resizedCanvas = new Canvas(resizedBitmap);
if (bitmap != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
resizedBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
Bundle parameters = new Bundle();
byte[] data = baos.toByteArray();
parameters.putByteArray("picture", data);
DataKeeper.getInstance().setBundleToPost(parameters);
}
bitmap.recycle();
它显示OutOfMemory 异常。我知道这是由于图像大小超出了其可用大小。如何在不损失质量的情况下调整图像大小?我尝试使用BitmapFactory.Options更正此问题。但不起作用。如何解决这个异常?
问候阿莎