【问题标题】:AS3 - Trying to resize a BitmapData but Matrix doesn't change anythingAS3 - 尝试调整 BitmapData 但 Matrix 没有改变任何东西
【发布时间】:2012-12-03 17:11:27
【问题描述】:

情况如下:在我的舞台上,我有一个引用 BitmapData 对象的 Bitmap 对象。我的位图对象是全屏的,所以是 1366x768。

另一方面,我有一个函数(来自一个库,所以我无法编辑它),它返回一个带有新图片的 BitmapData。那张图片是 640x480,每秒调用一次函数。

问题是:我找不到将返回的图片缩放到全屏的方法。我尝试使用 Matrix 和 .draw 方法,但什么也没做。

这里有一些代码:

var mat:Matrix = new Matrix();
mat.scale(0.52, 0.52); // I tried with other values such as 2 but the picture stays the same
// scr_bmp is the BitmapData attached to the displayed Bitmap
// capt.bmp is the BitmapData returned by the function
// I tried without the new Rectangle but that doesn't change anything
scr_bmp.draw(capt.bmp, mat, null, null,new Rectangle(0, 0, 640, 480), true);

使用此代码,新图片可以正确显示,但仍为原始尺寸:640x480,屏幕其余部分为空白。

提前感谢您的帮助!

【问题讨论】:

    标签: actionscript matrix resize bitmapdata


    【解决方案1】:

    嗯……

    mat.scale(scr_bmp.width/capt.bmp.width,scr_bmp.height/capt.bmp.height);
    var smallBitmap:Bitmap=new Bitmap(capt.bmp);
    scr_bmp.fillRect(scr_bmp.rect,0x00808080);
    scr_bmp.draw(smallBitmap,mat);
    

    刚刚尝试了不同的尺寸,但它对我有用。但我使用的是 AS3,而不是 AS2。

    【讨论】:

    • 天哪,非常感谢!您的代码指出了我的代码中的一个错误,该错误导致矩阵无法正常工作......
    猜你喜欢
    • 2020-10-24
    • 2023-02-02
    • 1970-01-01
    • 2019-08-17
    • 2019-05-26
    • 1970-01-01
    • 2021-03-17
    • 2020-01-19
    • 1970-01-01
    相关资源
    最近更新 更多