这是我的代码。附加图像时出现错误,内存不足
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