无法将 ImageSnapshot.captureBitmapData 与旋转矩阵一起使用
有谁有使用 ImageSnapshot.captureBitmapData 函数和旋转矩阵的示例吗? 这是我正在使用的代码:
var matrix:Matrix = new Matrix();
matrix.rotate(degreesToRadians(90));
var bitmapData:BitmapData = ImageSnapshot.captureBitmapData(textInput, matrix);
但不幸的是,这会在 ImageSnapshot.as 中的以下行上引发错误:
data = new BitmapData(scaledWidth, scaledHeight, true, 0x00000000); // <-- THROWS ERROR HERE AS scaledWidth / scaledHeight are extremely small numbers (-1-e16 etc)
data.draw(source, matrix, colorTransform,
blendMode, clipRect, smoothing);
}
finally
{
if (source is IUIComponent)
finishPrintObject(IUIComponent(source), normalState); // <-- ERROR THROWN HERE, BUT CAUSE OF ERROR IS ABOVE
}
我试图实现的是文本输入控件的旋转位图(我试图避免嵌入字体在应用程序中)。 当我不旋转位图时,这段代码工作得很好,但是当我旋转它时,它就崩溃了。
接受后答案编辑
我在最初的问题中使用了一个加载器类,并且我还想要文本 270 度 - 所以这里是执行此操作的文本:
var matrix:Matrix = new Matrix();
matrix.rotate(Math.PI * 1.5);
matrix.translate(0, copyThis.width);
var bitmapData:BitmapData = ImageSnapshot.captureBitmapData(copyThis, new Matrix());
var rotatedBitmap : BitmapData = new BitmapData(bitmapData.height, bitmapData.width, false, 0xFFFF0000);
rotatedBitmap.draw(bitmapData, matrix);
loader.load(new Bitmap(rotatedBitmap));
谢谢!
Does anyone have an example of using the ImageSnapshot.captureBitmapData function with a rotation matrix? This is the code I'm using:
var matrix:Matrix = new Matrix();
matrix.rotate(degreesToRadians(90));
var bitmapData:BitmapData = ImageSnapshot.captureBitmapData(textInput, matrix);
But unfortunately this throws an error on the following line in ImageSnapshot.as:
data = new BitmapData(scaledWidth, scaledHeight, true, 0x00000000); // <-- THROWS ERROR HERE AS scaledWidth / scaledHeight are extremely small numbers (-1-e16 etc)
data.draw(source, matrix, colorTransform,
blendMode, clipRect, smoothing);
}
finally
{
if (source is IUIComponent)
finishPrintObject(IUIComponent(source), normalState); // <-- ERROR THROWN HERE, BUT CAUSE OF ERROR IS ABOVE
}
What I'm trying to achieve is a rotated bitmap of a text input control (I'm trying to avoid embedding a font in the application). This code works just fine when I don't rotate the bitmap, but the minute I rotate it, it breaks.
Post-Accepted-Answer Edit
I was working with a loader class in my original problem, and I also wanted the text 270degrees - so here's the text which does that:
var matrix:Matrix = new Matrix();
matrix.rotate(Math.PI * 1.5);
matrix.translate(0, copyThis.width);
var bitmapData:BitmapData = ImageSnapshot.captureBitmapData(copyThis, new Matrix());
var rotatedBitmap : BitmapData = new BitmapData(bitmapData.height, bitmapData.width, false, 0xFFFF0000);
rotatedBitmap.draw(bitmapData, matrix);
loader.load(new Bitmap(rotatedBitmap));
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚能够重现这一点,所以它确实看起来像 ImageSnapshot 类中的错误。 我能想到的是,它只是没有使用旋转矩阵进行测试,所以它完全被错过了。 显然,尝试创建小于 1x1 的 bitmapData 是引发错误的原因。 老实说,无论如何似乎都无法解决这个问题。
认为您最好的选择可能是创建自己的简化快照类,或者仅使用单位矩阵来获取原始位图,然后将其复制到可以容纳旋转版本的新位图数据中。
编辑
另一点...由于 Flash 组件是从右上角注册的,因此您还需要将矩阵平移原始高度。 尽管这可能已经解决了最初的问题,但它仍然会崩溃。 这是一种使用新的 BitmapData 并转换由 ImageSnapshot 创建的 BitmapData 的解决方案
I have just been able to reproduce this so it indeed seems like bug in the ImageSnapshot class. All i can think of is that it's just not been tested using a rotation Matrix so it's been completely missed. Obviously trying to create a bitmapData less than 1x1 is the reason it's throwing the error. Can't seem anyway round it to be honest.
Would think your best bet could be to create your own simplified snap shot class, or to just use an identity matrix to get the original bitmap, and then copy that into a new bitmapData that can house the rotated version.
Edit
on another note... as flash components are registered from the top right, you also need to translate the matrix across by the original height. Though that may have solved the original problem but it still breaks. Here's a solution that uses a new BitmapData and transforms the one created by ImageSnapshot