java - .getPixel() 的更好替代方案?

标签 java android imaging

我在我的 Android 应用程序中使用此代码将位图转换为纯黑白,它可以工作:

public Bitmap ConvertToThreshold(Bitmap anythingBmap)
{
    int width = anythingBmap.getWidth();
    int height = anythingBmap.getHeight();
    int threshold = 120;
    for(int x=0;x<width;x++){
        for(int y=0;y<height;y++){

            int pixel = anythingBmap.getPixel(x, y);
            int gray = Color.red(pixel);
            if(gray < threshold){
                anythingBmap.setPixel(x, y, 0xFF000000);
            } else{
                anythingBmap.setPixel(x, y, 0xFFFFFFFF);
            }
        }
    }
    return anythingBmap;
}

如果 .getPixel() 非常慢,因此需要很长时间来处理,就会出现问题。有没有更快的方法?

谢谢

最佳答案

使用 public void getPixels (int[]pixels, int offset, int stride, int x, int y, int width, int height)。这将立即返回所有像素。

关于java - .getPixel() 的更好替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23903377/

相关文章:

Java加载文本文件

java - 为什么 EntityManager.merge() 会阻止 LazyInitializationException 而 EntityManager.find() 不会?

java - 客户端找不到 {} 的分派(dispatch)方法

android - 如何将Glide与onBindViewHolder集成?

python - Psychopy中的图像渲染问题

windows - 防止 GDI+ PNG 编码器将 Gamma 信息添加到 1 位 PNG

java - 我可以使用 spring Remember-me 在浏览器重新启动后恢复浏览器 session 而不使用复选框吗

android - 从改造 onResponse 返回数据

android - 在android中关闭webview

python - 如何使用 PIL(python 成像)创建透明 gif(或 png)