问题
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