【问题标题】:Java Android method taking a long time to execute?Java Android方法需要很长时间才能执行?
【发布时间】:2014-05-12 22:22:46
【问题描述】:

我正在创建一个非常简单的应用程序,当按下该应用程序时,它会将图片颜色更改为棕褐色滤镜。当我运行该应用程序时,一切正常,但图像更改需要近一分钟。你能快速看一下我的代码,看看你能不能告诉我为什么?

public class Pictue extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pictue);
        ImageButton button = (ImageButton) findViewById(R.id.imageButton1);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bitmap b1 =  BitmapFactory.decodeResource(getResources(), R.drawable.chin);
                b1 = createSepiaToningEffect(b1,10,7.00,6.00,3.00);
                ImageView chin = (ImageView) findViewById(R.id.imageView1)  ;
                chin.setImageBitmap(b1);
            }   
        });
    }

    public static Bitmap createSepiaToningEffect(Bitmap src, int depth, double red, double green, double blue) {
        int width = src.getWidth();
        int height = src.getHeight();
        Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
        final double GS_RED = 0.3;
        final double GS_GREEN = 0.59;
        final double GS_BLUE = 0.11;
        int A, R, G, B;
        int pixel;

        for(int x = 0; x < width; ++x) {
            for(int y = 0; y < height; ++y) {
                pixel = src.getPixel(x, y);
                A = Color.alpha(pixel);
                R = Color.red(pixel);
                G = Color.green(pixel);
                B = Color.blue(pixel);
                B = G = R = (int)(GS_RED * R + GS_GREEN * G + GS_BLUE * B);

                // apply intensity level for sepid-toning on each channel
                R += (depth * red);
                if(R > 255) { R = 255; }

                G += (depth * green);
                if(G > 255) { G = 255; }

                B += (depth * blue);
                if(B > 255) { B = 255; }

                bmOut.setPixel(x, y, Color.argb(A, R, G, B));
            }
        }

        return bmOut;
}
}   

【问题讨论】:

    标签: java android image filtering


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-03
      • 2011-03-14
      • 2021-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多