0

現在、ビットマップオブジェクトを取得し、色を取り除いてから赤くする次のコードがありますが、画像の暗い要素を暗くする必要があります。現時点では、誰かが画像の上に赤いフィルムを貼っているようです、これはほとんど私が望むものですが、黒をより暗くする必要があります:

Bitmap sourceBitmap = BitmapFactory.decodeFile(imgPath);
        float[] colorTransform = {
                0, 1f, 0, 0, 0, 
                0, 0, 0f, 0, 0,
                0, 0, 0, 0f, 0, 
                0, 0, 0, 1f, 0};
        ColorMatrix colorMatrix = new ColorMatrix();
        colorMatrix.setSaturation(0f); //Remove Colour 
        colorMatrix.set(colorTransform); //Apply the Red

        ColorMatrixColorFilter colorFilter = new ColorMatrixColorFilter(colorMatrix);
        Paint paint = new Paint();
        paint.setColorFilter(colorFilter);   

        Display display = getWindowManager().getDefaultDisplay(); 

        Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, (int)(display.getHeight() * 0.15), display.getWidth(), (int)(display.getHeight() * 0.75));            

        image.setImageBitmap(resultBitmap);

        Canvas canvas = new Canvas(resultBitmap);
        canvas.drawBitmap(resultBitmap, 0, 0, paint);
4

2 に答える 2

0

カラーマトリックスの最初の3つのrawの最後の列は、画像の明るさを変更します。[-255...255]の間で変更されました。-255は黒の画像になり、255は白になります。この方法では、コントラストを変えることができます。明るいオブジェクトよりも明るくなり、暗くなります。あなたがあなたの明るさをrequaredpoisitionに設定することができるより。コントラストが[-1...1]の間で変更されました。

private static void setContrast(ColorMatrix cm, float contrast) {
                float scale = contrast + 1.f;
                   float translate = (-.5f * scale + .5f) * 255.f;
                cm.set(new float[] {
                       scale, 0, 0, 0, translate,
                       0, scale, 0, 0, translate,
                       0, 0, scale, 0, translate,
                       0, 0, 0, 1, 0 });
        }
于 2013-02-25T08:21:21.863 に答える
0
c = 2;//this will boost your contrast by 2x thus deepening the black (and lightning the white). I'm not sure why at 0 you have anything but black... maybe I don't understand the matrix as well as I think I do... I thought 1 (in place of my c) gets you the original colors.

Anyway... give that a whirl. 


float[] colorTransform = {
                c, 1f, 0, 0, 0, 
                0, c, 0f, 0, 0,
                0, 0, c, 0f, 0, 
                0, 0, 0, 1f, 0};
于 2011-05-24T03:38:57.457 に答える