void imageProcessing()
{
// Creation of a "bitmap" object containing the pixels from "parrot.jpeg"
BitmapFactory bf1 = new BitmapFactory();
BitmapFactory.Options bfo1 = new BitmapFactory.Options();
bfo1.inMutable = true;
bfo1.inPreferredConfig = ARGB_8888;
bfo1.outConfig = ARGB_8888;
Bitmap bm1 = bf1.decodeFile("/storage/emulated/0/DCIM/parrot.jpeg", bfo1);
// Recording the image with the png format, as "parrot.png"
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
bm1.compress(Bitmap.CompressFormat.PNG, 100, outStream);
File f = new File("/storage/emulated/0/DCIM/parrot.png");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(outStream.toByteArray());
fo.flush();
fo.close();
} catch (FileNotFoundException e) {
Log.w("TAG", "Error saving image file: " + e.getMessage());
} catch (IOException e) {
Log.w("TAG", "Error saving image file: " + e.getMessage());
}
// Creation of a "bitmap" object containing the pixels from "parrot.png"
BitmapFactory bf2 = new BitmapFactory();
BitmapFactory.Options bfo2 = new BitmapFactory.Options();
bfo2.inMutable = true;
bfo2.inPreferredConfig = ARGB_8888;
bfo2.outConfig = ARGB_8888;
Bitmap bm2 = bf2.decodeFile("/storage/emulated/0/DCIM/parrot.png", bfo2);
// The 32 bits int which will contain values of red, green, blue, alpha
int pixel_color;
// The alpha, red, green, blue values
int alpha, red, green, blue;
// Color selected : full blue, with an alpha of 127 (the pixel will be half-transparent)
red = 0; green = 0; blue = 255; alpha = 127;
// Putting the A, R, G, B values into the int variable "pixel_color"
pixel_color = (alpha<<24) | (red<<16) | (green<<8) | blue;
// Modifying the (x=3,y=0) pixel with this color
bm2.setPixel(3, 0, pixel_color);
// Recording the modified image as "new_parrot.png"
ByteArrayOutputStream outStream2 = new ByteArrayOutputStream();
bm2.compress(Bitmap.CompressFormat.PNG, 100, outStream2);
File f2 = new File("/storage/emulated/0/DCIM/new_parrot.png");
try {
f2.createNewFile();
FileOutputStream fo = new FileOutputStream(f2);
fo.write(outStream2.toByteArray());
fo.flush();
fo.close();
} catch (FileNotFoundException e) {
Log.w("TAG", "Error saving image file: " + e.getMessage());
} catch (IOException e) {
Log.w("TAG", "Error saving image file: " + e.getMessage());
}
}