Flex/Actionscript图像显示问题

发布于 2024-08-29 08:43:20 字数 1450 浏览 2 评论 0原文

我正在尝试扩展 Image 类,但遇到了一个无法解决的问题。我有一个加载图像的私有图像(img)和一个获取该图像并将其复制到父级的函数。

调试功能“copyit2”可以很好地显示图像(所以我知道它已加载正常)。但函数“copyit”不起作用 - 它只显示一个白色矩形。我不知道如何使 copyit 工作,以便将原始图像复制到 BitmapData,然后复制到父级?

(这个想法是在显示位图数据之前对其进行一些处理,尽管为了使示例简单而没有在此处显示。)

我怀疑这与加载图像的安全性有关,但我正在加载它来自与应用程序运行相同的服务器 - 所以这应该不是问题?

感谢任何人可以提供的任何帮助。
伊恩

package zoomapackage
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.net.*;

    import mx.controls.Image;
    import mx.events.FlexEvent;

    public dynamic class Zooma extends Image
    {
        private var img:Image;

        public function copyit():void {
            var imgObj:BitmapData = new BitmapData(img.content.width, img.content.height, false);

            imgObj.draw(img);

            var matrix:Matrix = new Matrix();
            this.graphics.beginBitmapFill(imgObj, matrix, false,true);
            this.graphics.drawRect(0, 0, this.width , this.height);
            this.graphics.endFill();
        }

        public function copyit2():void {
            this.source = img.source;
        }

        public function Zooma()
        {
            super();
            img = new Image();
            img.load("http://localhost/Koala.jpg");
        }

    }
}

I'm trying to extend the Image class but hit a problem that I can't get past. I have a private image (img) that loads an image and a function that takes that image and copies it onto the parent.

The debug function "copyit2" displays the image fine (so I know it's loaded OK). But the function "copyit" doesn't work - it just displays a white rectangle. I can't see how to make copyit work so that the original image is copied to the BitmapData and then subsequenty copied onto the parent?

(The idea is to do some processing on the Bitmap data before it is displayed, although this isn't shown here to keep the example simple.)

I suspect it is something to do with the security of loading images, but I'm loading it from the same server as the application is run from - so this shouldn't be a problem?

Thanks for any help anyone can provide.
Ian

package zoomapackage
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.net.*;

    import mx.controls.Image;
    import mx.events.FlexEvent;

    public dynamic class Zooma extends Image
    {
        private var img:Image;

        public function copyit():void {
            var imgObj:BitmapData = new BitmapData(img.content.width, img.content.height, false);

            imgObj.draw(img);

            var matrix:Matrix = new Matrix();
            this.graphics.beginBitmapFill(imgObj, matrix, false,true);
            this.graphics.drawRect(0, 0, this.width , this.height);
            this.graphics.endFill();
        }

        public function copyit2():void {
            this.source = img.source;
        }

        public function Zooma()
        {
            super();
            img = new Image();
            img.load("http://localhost/Koala.jpg");
        }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘴硬脾气大 2024-09-05 08:43:20

修好了! (包括这一点,以防万一有人发现它有用)

该行:

imgObj.draw(img);

如果我将其更改为:

imgObj.draw(img.content);

在这方面失去了我生命的 2 天:-(

Fixed it! (Including this in case anyone finds it useful)

The line:

imgObj.draw(img);

works if I change it to:

imgObj.draw(img.content);

Lost 2 days of my life on that :-(

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文