如何获得一个阶段计算,调整图像大小W / R / TC [英] How to get a stage calculation to resize an image w/r/t c

查看:102
本文介绍了如何获得一个阶段计算,调整图像大小W / R / TC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想居中的图像在舞台中间,并将其按比例缩放到基于它的加载器的尺寸正确的纵横比当图像加载。

I am trying to center an image in the middle of the stage and scale it proportionally to the correct aspect ratio based on its loader's size when the image is loading.

在我的主要应用程序亚军我做的:

In my main app runner I do:

private var rec:Rectangle = new Rectangle();
private var img:BitmapDisplay = new BitmapDisplay();
stage.addEventListener(Event.RESIZE, setRect);
img.imageURL = "some/path/to/image.jpg";
addChild(img);

private function setRect():void
{
    var horz:Number = stage.stageWidth / 16;
    var vert:Number = stage.y + stage.stageHeight / 16;

    rec.x = horz;
    rec.y = 80;
    rec.width = stage.stageWidth - horz;
    rec.height = stage.stageHeight - (vert * 2) - rec.y;

    img.boundary = rec;
}

然后在我的图像(BitmapDisplay)I类有:

Then in my image (BitmapDisplay) class I have:

// sets the boundary of the image and resizes it
public function set boundary(rect:Rectangle):void 
{
    _imageBoundary = rect;
    resizeImage();
}

private function resizeImage():void 
{
    var aspect:Number = _ldr.content.width / _ldr.content.height;   
    var cAspect:Number = _imageBoundary.width / _imageBoundary.height;

    if (aspect <= cAspect) 
    {
        _ldr.height = _imageBoundary.height;
        _ldr.width = aspect * _ldr.height;
    }
    else 
    {
        _ldr.width = _imageBoundary.width;
        _ldr.height = _ldr.width / aspect;
    }

    var _pad:int = 7;

    _ldr.x = (_imageBoundary.width - _ldr.width) / 2 + _imageBoundary.x - _pad;
    _ldr.y = (_imageBoundary.height - _ldr.height) / 2 + _imageBoundary.y - _pad;
}
}   

有什么明显的保持这种从工作的权利? 我想在舞台的第16为的边界,该图像和图像在此基础上矩形缩放/调整大小。

Is there something obvious keeping this from working right? I want a 16th of the stage to be the bounds for the image and for the image to scale/resize based on this rect.

谢谢...

推荐答案

事实证明,这更多的是与加载程序还没有准备好进行调整。有一些错误检查我的code,它需要被重新格式化,所以现在当调整大小功能被调用,它不会做任何事情,直到装载机准备和边界设置。

It turns out that this had more to do with the loader not being ready to be resized. There was some error checking in my code that needed to be reformatted, so now when the resize function gets called, it doesn't do anything until the loader is ready and the boundary is set.

这篇关于如何获得一个阶段计算,调整图像大小W / R / TC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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