In my android project, I load a bitmap from a image in the phone. I then do various image manipulations to it like cropping, resizing, editing pixel values.
But the problem is the format of the bitmap is not ARGB_8888, so its not really storing the alpha values. Or rather its always keeping them at 255.
How can I load the bitmap in ARGB_8888 format? This is my code to load and resize. How can I specify the format in any of these?
Thanks
private static Bitmap resize(Bitmap img, int newW, int newH) throws IOException {
Bitmap resizedImg = Bitmap.createScaledBitmap(img, newW, newH, false);
img.recycle();
Bitmap newresizedImg = resizedImg.copy(Bitmap.Config.ARGB_8888, true);
resizedImg.recycle();
Pixel initialPixel = Function.getPixel(0, 0, newresizedImg, null);
int a = initialPixel.getColor().getAlpha(); // -> 255
newresizedImg.setPixel(0, 0, Pixel.getTransparentColor().getRGB());
initialPixel = Function.getPixel(0, 0, newresizedImg, null);
int new_a = initialPixel.getColor().getAlpha(); // -> 255
return newresizedImg;
}
private static Bitmap getImage(String from) throws IOException {
File file = new File(from);
if (file.exists()) {
BitmapFactory.Options op = new BitmapFactory.Options();
op.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bufferedImage = BitmapFactory.decodeFile(from, op);
return bufferedImage;
}
return null;
}
Pixel class
public static Color getTransparentColor() {
return new Color(0, 0, 0, 0);
}
Color class
public int getRGB() {
return ((A << 24) | 0xFF) + ((R << 16) | 0xFF) + ((G << 8) | 0xFF) + (B | 0xFF);
}