API级别<的Color.valueOf的替代方法26吗 [英] Alternative to Color.valueOf for API Level < 26?

查看:51
本文介绍了API级别<的Color.valueOf的替代方法26吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

是否有任何适用于21级以上API的库或类似内容?

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

推荐答案

使用

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

这篇关于API级别&lt;的Color.valueOf的替代方法26吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆