Image brightness increases even when you move the Seekbar scrollbar to the left

In my application, I want to change the brightness of an image in ImageView. For this purpose I use the search bar. It changes the brightness of the image when I move the scroll bar to the right, but when I want to decrease the brightness and move to the left, the brightness increases and the image becomes almost white. It is also so difficult to use the search barrier as a user. It does not move very smoothly. Can someone please help me improve my code as I am new to programming. This is how it looks when scrollbar of seekbar moved right (to increase brightness).This is how it looks when scrollbar of seekbar moved left (to decrease brightness).

Here is the piece of code:

When you click the filter button:

btn_filter.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
      Log.e("EditPhoto", "counter value = " + counter);
      counter++;
      sbarBrightness = (SeekBar) findViewById(R.id.seekBarForBrightness);
        if (counter % 2 == 0) {
            sbarBrightness.setVisibility(View.INVISIBLE);
        } else {
            sbarBrightness.setVisibility(View.VISIBLE);
        }
    sbarBrightness.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
     int brightness;
     @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean
                                          fromUser) {

    brightness = progress;
    imageBitmap = doBrightness(imageBitmap, brightness);
    putGestureImageOnScreen(imageBitmap);
 }
   });
  }
 });

public static Bitmap doBrightness(Bitmap src, int value) {
    Log.e("Brightness", "Changing brightnhjh");

    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bmout = Bitmap.createBitmap(width, height, src.getConfig());
    int A, R, G, B;
    int pixel;
    for (int i = 0; i < width; ++i) {
        for (int j = 0; j < height; ++j) {
            pixel = src.getPixel(i, j);
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            R += value;
            if (R > 255) {
                R = 255;
            } else if (R < 0) {
                R = 0;
            }
            G += value;
            if (G > 255) {
                G = 255;
            } else if (G < 0) {
                G = 0;
            }
            B += value;
            if (B > 255) {
                B = 255;
            } else if (B < 0) {
                B = 0;
            }
            bmout.setPixel(i, j, Color.argb(A, R, G, B));
        }
    }
    return bmout;

}

Search engine ad in layout:

<SeekBar
    android:id="@+id/seekBarForBrightness"
    android:layout_width="500dp"
    android:layout_height="50dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    style="@style/tallerBarStyle"        
    android:layout_marginTop="64dp"
    android:visibility="invisible" />

and this style is as follows:

<style name="tallerBarStyle" parent="@android:style/Widget.SeekBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
    <item
     name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
    <item name="android:minHeight">8dip</item>
    <item name="android:maxHeight">10dip</item>
</style>

, , , . - , .

.

+4
1

Bitmap (imageBitmap = doBrightness(imageBitmap, brightness);). , , .

brightness = progress;
//imageBitmap = doBrightness(imageBitmap, brightness);
putGestureImageOnScreen(doBrightness(imageBitmap, brightness));

Intent Activity , .

+2

Source: https://habr.com/ru/post/1528878/


All Articles