图像亮度需要太多时间才能点击

时间:2018-10-26 09:59:25

标签: android bitmap

嗨,在我的应用程序中正在显示一些主题。在该主题中,当按下任何图像时,与保留所有主题相比,图像背景都会变得明亮一些。

现在,我的问题是按下图像时需要在主线程上进行过多的工作。应该会在按下图像时快速操作。

任何人都可以帮助我解决此问题。

sample.java:

 mTick1.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.classic),-80));
                mTick2.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.casual1),-0));
                mTick3.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.natural),-0));
                mTick4.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.smart),-0));
                mTick5.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.meeting),-0));
                mTick6.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.cool),-0));
                mTick1.setVisibility(View.VISIBLE);
                mTick2.setVisibility(View.VISIBLE);
                mTick3.setVisibility(View.VISIBLE);
                mTick4.setVisibility(View.VISIBLE);
                mTick5.setVisibility(View.VISIBLE);
                mTick6.setVisibility(View.VISIBLE);
                mTick6.setVisibility(View.VISIBLE);

亮度方法:

public Bitmap SetBrightness(Bitmap src, int value) {
        // original image size
        int width = src.getWidth();
        int height = src.getHeight();
        // create output bitmap
        Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
        // color information
        int A, R, G, B;
        int pixel;

        // scan through all pixels
        for(int x = 0; x < width; ++x) {
            for(int y = 0; y < height; ++y) {
                // get pixel color
                pixel = src.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
                bmOut.setPixel(x, y, Color.argb(A, R, G, B));
            }
        }

        // return final image
        return bmOut;
    }

0 个答案:

没有答案