What code should I use with 'drawMatrix.setPolyToPoly' to manipulate and draw just a rectangular part of a bitmap, rather than the entire bitmap?

*爱你&永不变心* 提交于 2019-12-11 12:23:20

问题


When i want to use just part of a bitmap without skewing or rotating it, like the top left fourth, the following works well:

src_rect.set(0, 0, bmp_test.getWidth()/2,bmp_test.getHeight()/2);

canvas.drawBitmap(src_rect, dst_rectF, paint);

This draws just one fourth of the bitmap.

However, if i want to rotate or skew just part of a bitmap using a matrix, the following does not work as expected:

srcpairs[0] = 0;
srcpairs[1] = 0;
srcpairs[2] = (float)bmp_test.getWidth()/2;
srcpairs[3] = 0;
srcpairs[4] = (float)bmp_test.getWidth()/2;
srcpairs[5] = (float)bmp_test.getHeight()/2;
srcpairs[6] = 0;
srcpairs[7] = (float)bmp_test.getHeight()/2;

drawMatrix.setPolyToPoly(srcpairs, 0, dstpairs, 0, 4);
canvas.drawBitmap(bmp_test, drawMatrix, paint);

This does not just draw the top left forth of the bitmap, like

canvas.drawBitmap(src_rect, dst_rectF, paint) 

does. Instead it draws the entire bitmap, 4 times bigger than the dstpairs area, aligning the top left fourth of the bitmap (the srcpairs points) to the destpairs points.

What are the simplest changes to be made to this matrix code to manipulate and draw just a rectangular part of a bitmap?

I want to avoid creating separate bitmaps of parts of the original image. That is what I'm having to do now.

来源:https://stackoverflow.com/questions/33657423/what-code-should-i-use-with-drawmatrix-setpolytopoly-to-manipulate-and-draw-ju

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!