Struggling with this problem, I noticed that on some devices, the captured image was too big even for the display in the ImageView (there was a warning that the image is too wide for the texture), so I started working on changing its size on the server. usable size.
I will post all the code (at least the one that comes to photography and image manipulation), just in case
Here is the code to call the intent
public void takePhoto() { String directoryPath = DCIM_PATH; this.pictureFileName = Long.toHexString(System.currentTimeMillis())+".jpg"; String filePath = directoryPath + pictureFileName ; File directory = new File(directoryPath); if (!directory.exists()) { directory.mkdirs(); } this.imageUri = Uri.parse(filePath); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra( MediaStore.EXTRA_OUTPUT,Uri.fromFile( new File(filePath) ) ); startActivityForResult(intent, TAKE_PICTURE); } + "jpg."; public void takePhoto() { String directoryPath = DCIM_PATH; this.pictureFileName = Long.toHexString(System.currentTimeMillis())+".jpg"; String filePath = directoryPath + pictureFileName ; File directory = new File(directoryPath); if (!directory.exists()) { directory.mkdirs(); } this.imageUri = Uri.parse(filePath); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra( MediaStore.EXTRA_OUTPUT,Uri.fromFile( new File(filePath) ) ); startActivityForResult(intent, TAKE_PICTURE); } ; public void takePhoto() { String directoryPath = DCIM_PATH; this.pictureFileName = Long.toHexString(System.currentTimeMillis())+".jpg"; String filePath = directoryPath + pictureFileName ; File directory = new File(directoryPath); if (!directory.exists()) { directory.mkdirs(); } this.imageUri = Uri.parse(filePath); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra( MediaStore.EXTRA_OUTPUT,Uri.fromFile( new File(filePath) ) ); startActivityForResult(intent, TAKE_PICTURE); } ; public void takePhoto() { String directoryPath = DCIM_PATH; this.pictureFileName = Long.toHexString(System.currentTimeMillis())+".jpg"; String filePath = directoryPath + pictureFileName ; File directory = new File(directoryPath); if (!directory.exists()) { directory.mkdirs(); } this.imageUri = Uri.parse(filePath); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra( MediaStore.EXTRA_OUTPUT,Uri.fromFile( new File(filePath) ) ); startActivityForResult(intent, TAKE_PICTURE); } )) public void takePhoto() { String directoryPath = DCIM_PATH; this.pictureFileName = Long.toHexString(System.currentTimeMillis())+".jpg"; String filePath = directoryPath + pictureFileName ; File directory = new File(directoryPath); if (!directory.exists()) { directory.mkdirs(); } this.imageUri = Uri.parse(filePath); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra( MediaStore.EXTRA_OUTPUT,Uri.fromFile( new File(filePath) ) ); startActivityForResult(intent, TAKE_PICTURE); }
in onActivityResult I call the method to work with the newly made image
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case TAKE_PICTURE: if (resultCode == Activity.RESULT_OK) { loadImageJustTaken(imageUri); } break; } }
That said the method
public void loadImageJustTaken(Uri selectedImage) { mActivity.getApplicationContext().getContentResolver().notifyChange(selectedImage, null); Bitmap b = BitmapHelper.decodeFileToScaledBitmap(new File(imageUri.getPath()), Tapabook.IMG_WIDTH); ivPicture.setImageBitmap(b); ivPicture.setVisibility(View.VISIBLE); System.gc(); } notifyChange (selectedImage, null); public void loadImageJustTaken(Uri selectedImage) { mActivity.getApplicationContext().getContentResolver().notifyChange(selectedImage, null); Bitmap b = BitmapHelper.decodeFileToScaledBitmap(new File(imageUri.getPath()), Tapabook.IMG_WIDTH); ivPicture.setImageBitmap(b); ivPicture.setVisibility(View.VISIBLE); System.gc(); } IMG_WIDTH constant, so that larger images will fit in ImageView public void loadImageJustTaken(Uri selectedImage) { mActivity.getApplicationContext().getContentResolver().notifyChange(selectedImage, null); Bitmap b = BitmapHelper.decodeFileToScaledBitmap(new File(imageUri.getPath()), Tapabook.IMG_WIDTH); ivPicture.setImageBitmap(b); ivPicture.setVisibility(View.VISIBLE); System.gc(); } imageUri.getPath ()), Tapabook.IMG_WIDTH); public void loadImageJustTaken(Uri selectedImage) { mActivity.getApplicationContext().getContentResolver().notifyChange(selectedImage, null); Bitmap b = BitmapHelper.decodeFileToScaledBitmap(new File(imageUri.getPath()), Tapabook.IMG_WIDTH); ivPicture.setImageBitmap(b); ivPicture.setVisibility(View.VISIBLE); System.gc(); }
And here's the code for my class BitmapHelper
public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } "; public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } int WIDTH) throws IOException { public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } ); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } to jpg"); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } temp.jpg"); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } "); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } ; public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } "); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } "); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } int WIDTH) { public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } null, o); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } to public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } : [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT + "]"); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } / REQUIRED_WIDTH); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } " + e.getMessage ()); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } int WIDTH) { public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } : [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT + "]"); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } / REQUIRED_WIDTH); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } } bitmap"); public class BitmapHelper { private static final String LOGTAG = "BitmapHelper"; public static File scaleBitmapFile(File f, int WIDTH) throws IOException{ Log.d(LOGTAG, "scaleBitmapFile to WIDTH: " + WIDTH); Bitmap b2 = decodeFileToScaledBitmap( f, WIDTH); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); Log.d(LOGTAG, "scaleBitmapFile compress bitmap to jpg "); b2.compress(Bitmap.CompressFormat.JPEG,70 , outStream); File scaledBitmapFile = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg"); Log.d(LOGTAG, "scaleBitmapFile file: temp.jpg" ); scaledBitmapFile.createNewFile(); Log.d(LOGTAG, "scaleBitmapFile file CREATED" ); //write the bytes in file FileOutputStream fo = new FileOutputStream(scaledBitmapFile); fo.write(outStream.toByteArray()); Log.d(LOGTAG, "scaleBitmapFile file WRITTEN" ); // remember close de FileOutput fo.close(); Log.d(LOGTAG, "scaleBitmapFile file CLOSED" ); return scaledBitmapFile; } public static Bitmap decodeFileToScaledBitmap(File f, int WIDTH){ Log.d(LOGTAG, "decodeFileToScaledBitmap to WIDTH: " + WIDTH); try{ //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(new FileInputStream(f),null,o); //The new size we want to scale to final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = o.outWidth; final int ORIG_HEIGHT = o.outHeight; Log.d(LOGTAG, "decodeFileToScaledBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; //Decode with scaled height Log.d(LOGTAG, "decodeFileToScaledBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( BitmapFactory.decodeFile(f.getAbsolutePath()), REQUIRED_WIDTH, REQUIRED_HEIGHT, false); }catch (FileNotFoundException e) { Log.e(LOGTAG, "decodeFileToScaledBitmap FileNotFoundException: " +e.getMessage()); } return null; } public static Bitmap scaleBitmap(Bitmap b, int WIDTH){ final int REQUIRED_WIDTH=WIDTH; final int ORIG_WIDTH = b.getWidth(); final int ORIG_HEIGHT = b.getHeight(); Log.d(LOGTAG, "scaleBitmap original width: [" + ORIG_WIDTH + "] original height: [" + ORIG_HEIGHT+ "]"); final int REQUIRED_HEIGHT = ORIG_HEIGHT/( ORIG_WIDTH / REQUIRED_WIDTH ) ; Log.d(LOGTAG, "scaleBitmap returning scaled bitmap "); return Bitmap.createScaledBitmap( b, REQUIRED_WIDTH, REQUIRED_HEIGHT, false); } }
With it, I no longer have problems when taking on Samsung devices, older handhelds such as SG3 / Apollo, or the newer plates, such as SGTab 10.1. I hope this helps :)