1

私はhue効果コードを持っていて、それを で使用しseek barたいapplyHueFilter( bitmap, level )のですが、シークバーの円を右に移動すると色相フィルターが増加し、左に移動すると色相フィルターが減少します (削除します) ..

public static Bitmap applyHueFilter(Bitmap source, int level) {
    // get image size
    int width = source.getWidth();
    int height = source.getHeight();
    int[] pixels = new int[width * height];
    float[] HSV = new float[3];
    // get pixel array from source
    source.getPixels(pixels, 0, width, 0, 0, width, height);

    int index = 0;
    // iteration through pixels
    for(int y = 0; y < height; ++y) {
        for(int x = 0; x < width; ++x) {
            // get current index in 2D-matrix
            index = y * width + x;
            // convert to HSV
            Color.colorToHSV(pixels[index], HSV);
            // increase Saturation level
            HSV[1] *= level;
            HSV[1] = (float) Math.max(0.0, Math.min(HSV[1], 1.0));
            // take color back
            pixels[index] |= Color.HSVToColor(HSV);
        }
    }
    // output bitmap                
    myBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return myBitmap;        
}

当時、私はこれapplyHueFilterprogressChanged..

    hueSB.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            applyHueFilter(myBitmap, 100);
        }

        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        public void onStopTrackingTouch(SeekBar seekBar) {

        }

    });

右に動かすseekbarと色相が適用されますが、左に動かすと削除されません(減少します)..

4

2 に答える 2

4
Canvas canvas = new Canvas(yourbitmap);

        Paint paint = new Paint();
        paint.setColorFilter(ColorFilterGenerator.adjustHue(seekbarvalue));
        canvas.drawBitmap(yourbitmap, 0, 0, paint);
return yourbitmap;


public class ColorFilterGenerator
{

    public static ColorFilter adjustHue( float value )
    {
        ColorMatrix cm = new ColorMatrix();

        adjustHue(cm, value);

        return new ColorMatrixColorFilter(cm);
    }


    public static void adjustHue(ColorMatrix cm, float value)
    {

        value = (value % 360.0f) * (float) Math.PI / 180.0f;

        if (value == 0)
        {
            return;
        }
        float cosVal = (float) Math.cos(value);
        float sinVal = (float) Math.sin(value);
        float lumR = 0.213f;
        float lumG = 0.715f;
        float lumB = 0.072f;
        float[] mat = new float[]
                {
                        lumR + cosVal * (1 - lumR) + sinVal * (-lumR), lumG + cosVal * (-lumG) + sinVal * (-lumG), lumB + cosVal * (-lumB) + sinVal * (1 - lumB), 0, 0,
                        lumR + cosVal * (-lumR) + sinVal * (0.143f), lumG + cosVal * (1 - lumG) + sinVal * (0.140f), lumB + cosVal * (-lumB) + sinVal * (-0.283f), 0, 0,
                        lumR + cosVal * (-lumR) + sinVal * (-(1 - lumR)), lumG + cosVal * (-lumG) + sinVal * (lumG), lumB + cosVal * (1 - lumB) + sinVal * (lumB), 0, 0,
                        0f, 0f, 0f, 1f, 0f,
                        0f, 0f, 0f, 0f, 1f };
        cm.postConcat(new ColorMatrix(mat));
    }
}

このコードは、カラー フィルターを使用した色相効果に対して効率的に機能します。

于 2016-04-25T04:47:37.133 に答える
0

Simple logic error. You have applyHueFilter(myBitmap, 100);... you are increasing it by 100 no matter what.

It should be:

applyHueFilter(myBitmap, progress); 

Looking at the applyHueFilter method, you are also always doing HSV[0] *= level;, so no matter what, you are always increasing the hue, just by lesser or greater amounts.

于 2012-09-15T14:32:32.497 に答える