2

I'm trying to do perspective transformation on my bitmap with a given quadrilateral. However, the Matrix.polyToPoly function stretches not only the part of the image I want but also the pixels outside the given area, so that a huge image is formed in some edge cases which crashes my app because of OOM.

  • Is there any way to sort of drop the pixels outside of the said area to not be stretched?
  • Or are there any other possibilities to do a perspective transform which is more memory friendly?

I`m currenty doing it like this:

// Perspective Transformation
float[] destination = {0, 0,
        width, 0,
        width, height,
        0, height};

Matrix post = new Matrix();
post.setPolyToPoly(boundingBox.toArray(), 0, destination, 0, 4);
Bitmap transformed = Bitmap.createBitmap(temp, 0, 0, cropWidth, cropHeight, post, true);

where cropWidth and cropHeight are the size of the bitmap (I cropped it to the edges of the quadrilateral to save memory) and temp is said cropped bitmap.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
1resu
  • 514
  • 4
  • 11
  • 1
    you could try `Canvas#drawBitmapMesh` but i have no idea about how it behaves in terms of memory (you could also try `Canvas#drawVertices` but i really doubt any human ever tried that method :-) – pskink Nov 16 '17 at 09:29
  • Thanks a lot! This solved it for me. If anyone is curious, this post has all the necessary code: https://stackoverflow.com/questions/36308856/distorting-an-image-to-a-quadrangle-fails-in-some-cases-on-android – 1resu Nov 23 '17 at 14:39

1 Answers1

0

Thanks to pskink I got it working, here is a post with the code in it:

Distorting an image to a quadrangle fails in some cases on Android

1resu
  • 514
  • 4
  • 11