To Create a new bitmap from a old one in android


To Create a new bitmap from a old one

BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();

bmpFactoryOptions.inJustDecodeBounds = true;

Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions);


// Create a New Bitmap which has the same width and heigth of the old

Bitmap alteredBitmap = Bitmap.createBitmap(bmp.getWidth(),bmp.getHeight(),bmp.getConfig());

// Canvas is used for drawing...

Canvas canvas = new Canvas(alteredBitmap);
Paint paint = new Paint();

canvas.drawBitmap(bmp, 0, 0, paint);

ImageView alteredImageView = (ImageView) this.findViewById(R.id.AlteredImageView);

alteredImageView.setImageBitmap(alteredBitmap);

//The drawBitmap method on the Canvas object we are using takes the source Bitmap and
//an x, y offset along with our Paint object. This causes our alteredBitmap object to
//contain the exact same information as our original bitmap.