Alternative to Color.valueOf for API Level < 26?

余生长醉 提交于 2021-01-26 03:57:40

问题


I'm currently working with Bitmap and trying to make some operation on pixels. I wanted to use Color.argb() and Color.valueOf() but those doesn't work for API Level < 26.

Is there any library or something similar that could work with any API Level > 21 ?

Here is the part of the function I use :

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());
}

回答1:


Use the version of argb() that takes int instead of float. That has been around since API Level 1.



来源:https://stackoverflow.com/questions/52027320/alternative-to-color-valueof-for-api-level-26

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!