我怎样才能准确地画出我的旋转位图? [英] How can I accurately draw my rotated bitmap?

查看:112
本文介绍了我怎样才能准确地画出我的旋转位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有它蒙面位图的容器。的规模和在运行时此容器旋转的变化,我需要绘制蒙面位图,但不能找出合适的矩阵计算这样做。

I have a container with masked bitmap in it. The scale and rotation of this container changes at runtime, and I need to draw the masked bitmap but cannot figure out the appropriate matrix calculations to do so.

我的code正常工作,以反映的位置,规模,对于没有中心旋转偏移。当旋转时,角度是正确的,但在定位是不正确的 - 我相信,因为当矩形被旋转的尺寸改变

My code works correctly to reflect position, scale, offset for centering without rotation. When rotated, the angle is correct but the positioning is incorrect - I believe because the dimensions change when the rectangle is rotated.

有人可以帮助我弄清楚如何弥补这一点在定位 - 这里是一些code:

Can someone help me figure out how to compensate for this in the positioning - here is some code:

 // Adjust the transformation matrix to account for the position of the container
        var tMatrix:Matrix = _imgContainer.transform.matrix;

        //Offset for container
        tMatrix.translate(this.x,this.y);

        //Offset for bounds centering
        tMatrix.translate(-_imgContainer.width/2,-_imgContainer.height/2);   

       // Compensate for rotation
       // ????

   var result_bitmap:BitmapData = new BitmapData(_maskedImg.width,_maskedImg.height,true,0x00FFFFFF);
   result_bitmap.lock();
   result_bitmap.draw(_maskedImg,tMatrix,null,null,null,true);
   result_bitmap.unlock();

在此先感谢您的帮助,您可以提供 -

Thanks in advance for any help you can provide -

B

编辑: 很抱歉,如果我没有正确地解释这一点,让我用图像来支持再试一次。我在我使用的源头上绘制新位图容器的蒙面位图。此容器可以缩放/在运行时之前,通过捕捉用户旋转。为了实现这一点,我通过拉伸方法基于所述容器矩阵变换矩阵和调整而tx和ty值以考虑非零原点(由于定心)。到现在为止它工作正常,并且捕获了我所期望的。

Sorry if I'm not explaining this correctly, let me try again with an image to support. I have a masked bitmap in a container which I'm using as the source to draw a new bitmap. this container can be scaled/rotated at runtime by the user prior to capturing. In order to accomplish this I pass the draw method a transformation matrix based on the container matrix and adjust the tx and ty values to account for the non-zero origin (due to centering). Up to this point it works fine and captures what I would expect.

不过 - 一旦这个容器旋转时,捕获的位置现在已经关闭了 - presumable由于尺寸变化的,因此,TX / TY偏移现在是不正确的容器新的层面。我只是要弥补这一点,但无法弄清楚如何。

However - once this container is rotated, the POSITION of the capture is now off again - presumable due to the dimensions changing, therefore the tx/ty offsets now being incorrect for the new dimensions of the container. I simply need to compensate for this, but cannot figure out how.

有没有人有转换矩阵,可以帮助经验?再次感谢您的努力!

Does anyone have experience with the transform matrix that can help?? Thanks again for the effort!

推荐答案

FYI任何人都可能同来类似的问题。我通过明确设置转换矩阵值,并在此特定的顺序的缩放,旋转然后平移。

FYI for anyone that might come along with similar problems. I solved my issue by explicitly setting the transformation matrix values and in this specific order scale, rotation then translation.

这是不是照搬从容器中变换矩阵。因此,而不是

This was instead of copying the transformation matrix from the container. So instead of

var tMatrix:Matrix = _imgContainer.transform.matrix;

我直接按以下顺序设置的值:

I am setting the values directly in this order:

tMatrix.scale (_imgContainer.scaleX, _imgContainer.scaleY);
tMatrix.rotate (_imgContainer.rotation * (Math.PI/180));
tMatrix.translate (_imgContainer.x, _imgContainer.y);

感谢您的努力 -

Thanks for the effort -

B

这篇关于我怎样才能准确地画出我的旋转位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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