我应该用'drawMatrix.setPolyToPoly“用什么code操作和绘制位图的只是一个长方形的一部分,而不是整个的位图? [英] What code should I use with 'drawMatrix.setPolyToPoly' to manipulate and draw just a rectangular part of a bitmap, rather than the entire bitmap?

查看:284
本文介绍了我应该用'drawMatrix.setPolyToPoly“用什么code操作和绘制位图的只是一个长方形的一部分,而不是整个的位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想只使用位图的一部分,无需倾斜或旋转它,就像上面留下第四,下面的效果很好:

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) 

一样。代替它绘制整个位图,比dstpairs面积大4倍,对准位图的左上角第四(该srcpairs分)destpairs点

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.

什么是操作和绘制位图的只是一个长方形的一部分,这个矩阵code要做出的最简单的变化?

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.

推荐答案

嗯,这正是 Matrix.setPolyToPoly(浮动[] SRC,诠释SRCINDEX,浮动[] DST,INT DSTINDEX,INT pointCount)一样。它的的src 点映射到 DST 点完全吻合。

Well, that is exactly what Matrix.setPolyToPoly(float[] src, int srcIndex, float[] dst, int dstIndex, int pointCount) does. It maps the src points onto the dst points exactly.

在你的的src 要点:您已设置位的1/4。我在你的 DST 点怀疑,你已经设置了完整的位图,这是4倍的1/4图像(4因而大倍)。你可以发布你的 dstpairs 也?同时发布的值bmp_test.getWidth() canvas.getWidth()分别高峰。

In your src points: You have set 1/4th of the bitmap. I suspect in your dst points, you have set the full bitmap, which is 4 times your 1/4th image (Hence 4 times bigger). Could you post your dstpairs also? Also post the values of bmp_test.getWidth() and canvas.getWidth() and the heights respectively.

如果您已映射的SRC点和DST点同一区域,则不会缩放来完成。你可以进行位图roatation如果你映射到相应的 DST 点,保持该地区稳定。

If you have mapped the "same area" of src points and dst points, then scaling wont be done. You could perform roatation of bitmap if you map to appropriate dst points, keeping the area constant.

这篇关于我应该用'drawMatrix.setPolyToPoly“用什么code操作和绘制位图的只是一个长方形的一部分,而不是整个的位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆