如何降低与android位图的对比度?

时间:2014-08-12 14:36:46

标签: android image-processing brightness contrast

这是我用来改变图像对比度和亮度的代码。我可以增加和减少图像的亮度,因为它需要-255到255的亮度值,我可以用0到10的值增加对比度,但是我不能降低对比度,因为这个代码没有 - 对比的价值。那么如何降低对比度?

/**
         * 
         * @param bmp input bitmap
         * @param contrast 0..10 1 is default
         * @param brightness -255..255 0 is default
         * @return new bitmap
         */
        public static Bitmap changeBitmapContrastBrightness(Bitmap bmp, float contrast, float brightness)
        {
            ColorMatrix cm = new ColorMatrix(new float[]
                    {
                        contrast, 0, 0, 0, brightness,
                        0, contrast, 0, 0, brightness,
                        0, 0, contrast, 0, brightness,
                        0, 0, 0, 1, 0
                    });

            Bitmap ret = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());
            Canvas canvas = new Canvas(ret);
            Paint paint = new Paint();
            paint.setColorFilter(new ColorMatrixColorFilter(cm));
            canvas.drawBitmap(bmp, 0, 0, paint);
            return ret;
        }

0 个答案:

没有答案