我有一个色相
效果code,我想用它与搜索栏
中,效果可以使用适用 applyHueFilter(位图,级)
我想,当我移动搜索栏圈向右色调滤镜增加,当我移动到左侧的色彩过滤器减少(删除)。
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 right the hue filter increases and when i move it to the left the hue filter decreases ( removes ) ..
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;
}
当时的即时通讯使用该 applyHueFilter
在 progressChanged
..
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) {
}
});
会发生什么情况是,当我移动搜索栏
到正确的色调applys但是当我将它移动到离开它不会被删除(降低)..
what happens is when i move the seekbar
to the right the hue applys but when i move it to the left it doesn't get removed ( decreased ) ..
简单的逻辑错误。您有 applyHueFilter(MYBITMAP,100);
...你增加它由100无论是什么
Simple logic error. You have applyHueFilter(myBitmap, 100);
... you are increasing it by 100 no matter what.
这应该是:
applyHueFilter(myBitmap, progress);
纵观 applyHueFilter
方法,你也总是在做 HSV [0] * =水平;
,所以不管是什么,你总是增加了色相,只是或大或小的数额。
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.