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.