這是我的代碼。附加圖像時出現錯誤,內存不足
case RESULT_MEMORY_SELECT: //SELECTING IMAGE FROM SD CARD
Uri photoUri = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(photoUri, filePathColumn, null, null, null);
if (cursor.moveToFirst())
{
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Bitmap imageReturned = BitmapFactory.decodeFile(filePath);
showViewOfReceiptInLayout(imageReturned);
}
break;
public void showViewOfReceiptInLayout(Bitmap imageBitmap)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageSelected = baos.toByteArray(); // imageSelected is byteArray and i am storing this byte array in Database
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, 72, 72, false);
image.setVisibility(View.VISIBLE); // For Visible
image.setImageBitmap(imageBitmap);
02-29 10:30:44.496: E/AndroidRuntime(7682): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-29 10:30:44.496: E/AndroidRuntime(7682): at android.graphics.Bitmap.nativeCreate(Native Method)
02-29 10:30:44.496: E/AndroidRuntime(7682): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
02-29 10:30:44.496: E/AndroidRuntime(7682): at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
有誰能告訴如何解決這個錯誤?
不會失去質量嗎?我不想減少我將要存儲在數據庫 – 2012-02-29 06:07:58
中的圖像的大小和質量,但是根據我的意見,您將沒有別的選擇。 – Maneesh 2012-02-29 06:15:18