图像一次重绘一个像素

时间:2014-05-12 14:57:43

标签: android image-processing

我想拍摄一张照片,获取每个像素,将其更改为另一种颜色并更新屏幕上的图像。

我可以做所有这些,除了屏幕在每个像素之后都没有更新,它只是在循环结束时更新 - 我假设操作系统或Java正在为幕后操作这个并在完成时简单地向我展示最终结果。

有谁知道我如何强制用户界面显示图像实时变化?

这是我在点击监听器中的情况。       operation = Bitmap.createBitmap(bmp.getWidth(),       bmp.getHeight(),bmp.getConfig());

  for(int i=0; i<bmp.getWidth(); i++){
     for(int j=0; j<bmp.getHeight(); j++){
        int p = bmp.getPixel(i, j);
        int r = Color.red(p);
        int g = Color.green(p);
        int b = Color.blue(p);
        int alpha = Color.alpha(p);



        r = (int) (Math.log(r)  +  r);
        g = (int) (Math.log(g)  + g);
        b = (int) (Math.log(b)  + b);
        alpha = (int) (Math.log(alpha) + alpha);

        operation.setPixel(i, j, Color.argb(alpha, r, g, b));

     }
     img.setImageBitmap(operation);

1 个答案:

答案 0 :(得分:0)

试试这个:

for(int i=0; i<bmp.getWidth(); i++){
     for(int j=0; j<bmp.getHeight(); j++){
        int p = bmp.getPixel(i, j);
        int r = Color.red(p);
        int g = Color.green(p);
        int b = Color.blue(p);
        int alpha = Color.alpha(p);

        r = (int) (Math.log(r)  +  r);
        g = (int) (Math.log(g)  + g);
        b = (int) (Math.log(b)  + b);
        alpha = (int) (Math.log(alpha) + alpha);

        operation.setPixel(i, j, Color.argb(alpha, r, g, b));
        img.setImageBitmap(operation);
        img.invalidate();
     }
 }