简体   繁体   English

Android位图像素操作返回黑色正方形

[英]Android Bitmap Pixel operations return black square

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. 我已经检查了Color.colorToHSV()方法是否可以正常工作。 So apparently the problem lies within either Color.HSVToColor() or newBitmap.setPixel() 因此,显然问题出在Color.HSVToColor()或newBitmap.setPixel()

Can anyone help me with this? 谁能帮我这个?

Maybe the new image have transparency, that is multipied with hsv. 也许新图像具有透明度,即与hsv相乘。 Try to set tranparency in Color ARGB. 尝试在彩色ARGB中设置透明度。 Or maybe youst change image type from ARGB to RGB. 或者,也许您将图像类型从ARGB更改为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. 也可以在多倍乘以1.5后尝试添加检查,以使结果不超过1,如果不超过1,则将其设置为1。您也可以尝试将相乘的像素设置回原始图片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM