Using Hue Image Effect With A Seekbar
I have a hue effect code and I want to use it with a seek bar, the effect can be applied using applyHueFilter( bitmap, level ) I want when i move the circle of the seekbar to the r
Solution 1:
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));
}
}
this code is efficiently work for Hue effect using Color Filter.
Solution 2:
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.
Post a Comment for "Using Hue Image Effect With A Seekbar"