API级别<26的Color.valueOf的替代方法?

Kam*_*ops 5 android colors bitmap

我目前正在使用Bitmap,并尝试对像素进行一些操作。我想使用Color.argb()Color.valueOf()但是对于API Level <26而言,这些功能不起作用。

是否有任何库或类似的东西可以与任何API Level> 21一起使用?

这是我使用的部分功能:

int width =  myBitmap.getWidth();
int height = myBitmap.getHeight();
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int [] allpixels = new int [ bmp.getHeight()*bmp.getWidth()];
myBitmap.getPixels(allpixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(),bmp.getHeight());
bmp.setPixels(allpixels, 0, width, 0, 0, width, height);

for(int i =0; i<bmp.getHeight()*bmp.getWidth();i++) {
    allpixels[i] = Color.argb(
        Color.valueOf(allpixels[i]).red(),
        Color.valueOf(allpixels[i]).red(),
        Color.valueOf(allpixels[i]).green(),
        Color.valueOf(allpixels[i]).blue());
}
Run Code Online (Sandbox Code Playgroud)

Com*_*are 5

使用that take 的版本而不是argb()intfloat。从API级别1开始就存在这种情况。