I\'m trying to make a basic application that displays an image from the camera, but I when I try to load the .jpg in from the sdcard with BitmapFactory.decodeFile
Well after working a lot i found out that the problem was not with code but the ram size of emulator, editing avd and increasing ram size solves all problems and saves huges pics easily. thanks.
send:
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, o);
int REQUIRED_SIZE = 640;
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while(true) {
if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE) break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
Bitmap bitmap = BitmapFactory.decodeFile(filePath, o2);
ByteArrayOutputStream bs2 = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, bs2);
getIntent().putExtra("byte_picture", bs2.toByteArray());
recive:
Bitmap photo = BitmapFactory.decodeByteArray(data.getByteArrayExtra("byte_picture"),0,data.getByteArrayExtra("byte_picture").length);
Here is another solution that uses inSampleSize and dynamically determines the image resolution to use based on available memory:
http://bricolsoftconsulting.com/handling-large-images-on-android/
Try to set the inSampleSize as shown in this example.
You can follow this amazing tutorial
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html