Reputation: 253
I have a method which is supposed to change Saturation and Lightness for all pixels of a bitmap. Code:
public static Bitmap change(Bitmap b){
Bitmap newBitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888);
for(int x = 0; x < newBitmap.getWidth(); x++){
for(int y = 0; y < newBitmap.getHeight(); y++){
float[] hsv = new float[3];
Color.colorToHSV(b.getPixel(x, y), hsv);
hsv[1] *= 1.5f;
hsv[2] *= 1.5f;
newBitmap.setPixel(x, y, Color.HSVToColor(hsv));
}
}
return newBitmap;
}
But when I run it, it just returns a completely black bitmap.
I have already checked if the Color.colorToHSV() method works, it does. So apparently the problem lies within either Color.HSVToColor() or newBitmap.setPixel()
Can anyone help me with this?
Upvotes: 1
Views: 227
Reputation: 6412
Maybe the new image have transparency, that is multipied with hsv. Try to set tranparency in Color ARGB. Or maybe youst change image type from ARGB to RGB. Also try to add checks after multyplying by 1.5, that the result not exceed 1, and if does, set it to 1. You could also try, set the multiplied pixels back to original picture.
Upvotes: 1