如何增加按钮的亮度?

时间:2018-10-29 06:39:50

标签: android bitmapfactory brightness

嗨,我有一个应用程序,当我尝试触摸任何按钮时,与保留所有按钮相比,它应该更亮。

我已经尝试过一种代码,它可以正常工作。但是,它花费了太多的时间来显示。

任何人都可以告诉我其他方式吗?

if (themeClick.equals("6")) {/*cool*/
                mTick1.setVisibility(View.VISIBLE);
                mTick2.setVisibility(View.VISIBLE);
                mTick3.setVisibility(View.VISIBLE);
                mTick4.setVisibility(View.VISIBLE);
                mTick5.setVisibility(View.VISIBLE);
                mTick6.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.cool),-80));
                mTick1.setImageBitmap(SetBrightness(BitmapFactory.decodeResource(getResources(), R.drawable.classic),-0));
                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.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 个答案:

没有答案