0

I'm trying to clear unwanted area from picture, in the most efficient way,

My code for now:

Bitmap picture = ...;
ByteBuffer mask = ...;
int height = picture.getHeight();
int width = picture.getWidth();
for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
        float currFloat = mask.getFloat();
        if (currFloat > 0.7) {
            req.setPixel(x, y, Color.TRANSPARENT);
        }
    }
}

My mask (ByteBuffer of (for example) 8*8):

mask

My picture (Bitmap of 8*8):

enter image description here

Excepted result:

enter image description here

Thankfully, it works, but unfortunately it takes too long since there are a lot of images to process..

There is any way to make it work faster? (something like matrix multiplication?)

I can transform the bitmap into buffer using

picture.copyPixelsToBuffer(buff)

Thanks in advance.

Nirel
  • 1,855
  • 1
  • 15
  • 26
  • 1
    consider using JNI and doing the work in C/C++, see https://stackoverflow.com/questions/14398670/rotating-a-bitmap-using-jni-ndk for example – CSmith Jul 30 '21 at 13:05
  • C and JNI are your best answers, but even just avoiding setPixel and using getPixels() to get an array of pixels and modifying that directly would be a big speedup. – Gabe Sechan Jul 30 '21 at 13:52
  • I do not understand that you would put floats in a ByteBuffer. – blackapps Jul 30 '21 at 13:58

0 Answers0