0

So, what I am trying to do is if I click the button, it will tint a image that is on the same screen with orange color (70%).

    Button OrangeButton= (Button) findViewById(R.id.OButton);
    OrangeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            imageCapture = (ImageView) findViewById(R.id.imageCapture);
            BitmapDrawable drawable = (BitmapDrawable) imageCapture
                    .getDrawable();
            final Bitmap imgbitmap = drawable.getBitmap();
            // convert bitmap to hokie tint
            Bitmap imgnew;
            imgnew = toOrange(imgbitmap);

            // convert bitmap to imageview
            imageCapture.setImageBitmap(imgnew);
        }
    });

}

Here is my orange method.

public Bitmap toOrange(Bitmap bmpOriginal) {
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();
    int orangeFilter = new Color().rgb(255, 165, 0);
    int maroonFilter = new Color().rgb(115, 24, 44);
    for (int j = 0; j < height - 1; j++) {
        for (int i = 0; i < width - 1; i++) {

I am pretty sure that I have a problem, here.

        int newColor = (int) (bmpOriginal.getPixel(i, j) * 0.7 + orangeFilter
                * 0.3);
        bmpOriginal.setPixel(i, j, newColor);
            }

    }
    return bmpOriginal;
}

I tried bmpOriginal.setPixel(5, 5, Color.Red) outside of this loob, and it made an error too. So I know that the setPixel is not working. How can I fix this problem?

Jieun Chon
  • 139
  • 1
  • 10

1 Answers1

0

Since you're not posting what exactly the error is, I'm assuming that the Bitmap is immutable, which means you can't change it. You could try making a mutable copy of it, see http://developer.android.com/reference/android/graphics/Bitmap.html

An easier way could be to apply a color filter to your ImageView like so:

imageCapture.setColorFilter(Color.rgb(255, 165, 0));
ci_
  • 8,594
  • 10
  • 39
  • 63