开发者

Scaling larger Image problem

开发者 https://www.devze.com 2022-12-23 23:58 出处:网络
I m developing flex application, in which I want to Draw Image from User local hard-drive to the canvas of size 640x360.

I m developing flex application, in which I want to Draw Image from User local hard-drive to the canvas of size 640x360.

User can choose Image of bigger resolution & is scaled to Canvas size.

But if user selected ima开发者_Go百科ges of larger resolution like 3000x2000, the scaling take lot time & freezes the application until scale done.

Is there any method to scale image faster or kind of threading can be done?

I am using matrix to scale Image as below:

    var mat:Matrix = new Matrix();
    var scalex:Number = canvasScreen.width/content.width;
    var scaley:Number = canvasScreen.height/content.height;
    mat.scale(scalex,scaley);           

    canvasScreen.graphics.clear();      
    canvasScreen.graphics.beginBitmapFill(content.bitmapData,mat);


Why dont you set the 'scaleContent' property on the Image tag... Images will be scaled to fit into your Image tag.


I think your problem is the use of the Image, I am developing an application that loads images on a canvas and scale them but there works fine for big resolution I will write some code maybe it will help you:

public class ImageObject extend Canvas
{
    public var image :Image;

    ..................
    ..................

    override protected function childrenCreated() : void
    {
        super.childrenCreated();
        addChild( image );
    }

    public function scaleImage():void
    {
        // Caluculate your xVal and yVal here

        var m:Matrix = new Matrix();
        m.scale( xVal, yVal );
        m.concat( image.transform.matrix );

        image.transform.matrix = m;
    }
}

And if you can't add the image as a child to ImageObject you should try making 2 containers for ex:

public class ImageObject extend Canvas
{

public var imageContainer :Canvas;
public var otherContainer :Canvas;

...........................
...........................

override protected function childrenCreated() : void
{
        super.childrenCreated();
        addChild( imageContainer); // add here your image
        addChild( otherContainer ); // here other objects
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号