gpt4 book ai didi

android - 增加/减少android中图像的每个 channel 会变慢

转载 作者:行者123 更新时间:2023-11-29 18:07:18 25 4
gpt4 key购买 nike

我正在尝试使用这段代码实现一些图像过滤器

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

imageView=(ImageView) findViewById(R.id.imgView);
bgr = BitmapFactory.decodeResource(getResources(), R.drawable.test02);


int A, R, G, B;
int pixel;

// scan through all pixels
for(int x = 0; x < bgr.getWidth(); ++x)
{
for(int y = 0; y < bgr.getHeight(); ++y)
{
// get pixel color
pixel = bgr.getPixel(x, y);
A = Color.alpha(pixel);
R = Color.red(pixel);
G = Color.green(pixel);
B = Color.blue(pixel);

// increase/decrease each channel
R += value;
if(R > 255) { R = 255; }
else if(R < 0) { R = 0; }

G += value;
if(G > 255) { G = 255; }
else if(G < 0) { G = 0; }

B += value;
if(B > 255) { B = 255; }
else if(B < 0) { B = 0; }

// apply new pixel color to output bitmap
bgr.setPixel(x, y, Color.argb(A, R, G, B));
}
System.out.println("x");
}

imageView.setImageBitmap(bgr);

}

问题是这是是做它的任何其他方式,或者让它更快..

最佳答案

您应该阅读有关使用 ColorMatrix 的内容。该矩阵可以准确执行您手动执行的操作。在您的情况下,由于您只是向每个组件添加一个常量值,因此您的矩阵将具有 a = g = m = s = 1e = j = o = value,矩阵的其余部分将为零。

然后你可以使用setColorFilter()申请 ColorMatrixColorFilter到你的 ImageView。

关于android - 增加/减少android中图像的每个 channel 会变慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12740042/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com