使用 as3 在 Flex 中调整图像大小 [英] Resize images in Flex using as3

查看:27
本文介绍了使用 as3 在 Flex 中调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用加载器加载图像.加载后,我可以使用 Bitmap(event.target.loader.content).bitmapData 获取位图数据.

I am loading an image using a Loader. Once loaded, I can get the bitmap data using Bitmap(event.target.loader.content).bitmapData.

然而,由于我加载的图像非常大(大约 2000 x 1600),我想减小尺寸并创建一个新的较小的位图,可能是 200 或 300 像素宽,有点像缩略图.

However since the images I am loading are quite large (around 2000 x 1600), I would like to reduce the size and create a new smaller bitmap maybe 200 or 300 pixels wide, sort of like a thumbnail.

我认为这与创建具有新大小的新 BitmapData 有关.但是,我无法使其正常工作.

I think it has to do with creating a new BitmapData with the new size. However I am not able to get that working properly.

有什么想法吗?

推荐答案

未测试,但应该给你一个想法:

Not tested, but this should give you an idea:

public function scaleBitmap(src: BitmapData, ratio: Number): BitmapData
{
    var bmd: BitmapData = new BitmapData(src.width * ratio, src.height * ratio);
    var m: Matrix = new Matrix();   
    m.scale(ratio, ratio);
    bmd.draw(src, m);
    return bmd;
}

这篇关于使用 as3 在 Flex 中调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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