jpegencoder.swc 来自 http://last.instinct.se/graphics-and-effects/using-the-fast-asynchronous-alchemy-jpeg-encoder-in-flash/640

发布于 2024-12-05 09:19:50 字数 1343 浏览 0 评论 0原文

有人在flashbuilder 4.5.1中成功使用过这个编码器吗? 我收到这个错误???通常在加载第二张图片时。任何帮助表示赞赏。

RangeError: Error #1506: The specified range is invalid. 
at cmodule.aircall::FSM_imalloc$/start() 
at cmodule.aircall::FSM_pubrealloc/work() 
at cmodule.aircall::CRunner/work() 
at Function/<anonymous>() 
at flash.utils::Timer/_timerDispatch() 
at flash.utils::Timer/tick() 

我的代码如下:

private var im:img; 
private var jpgStream:ByteArray; 
private var jpeglib:Object; 
private var jpeginit:CLibInit = new CLibInit(); // get library 

public function save_image(_im:img, pg:Number):void 
{ 
     var bm:BitmapData = Bitmap(_im.getChildAt(0)).bitmapData; 
     im = _im; 

     var imgData:ByteArray = bm.getPixels(bm.rect); 
     jpgStream = new ByteArray(); 
     imgData.position = 0; 

     trace(bm == null); 
     var jpegQuality:Number = 40; 

     if (!jpeglib) { 
          jpeglib=jpeginit.init(); 
     } 
     jpeglib.encodeAsync(encodeComplete, imgData, jpgStream, bm.width, bm.height, jpegQuality); 
} 

private function encodeComplete(e:Event):void { 
     trace("Encoding complete"); 

     file = File.documentsDirectory.resolvePath("Pic-A-Note/" + albumName + "/object_layer_" + im.name + ".pn"); 
     fs.open(file, FileMode.WRITE); 
     fs.writeBytes(jpgStream,0); 
     fs.close(); 
}

Has anyone succesfully used this encoder in flashbuilder 4.5.1?
I'm getting this error??? usually on loading up a second pic. any help is appreciated.

RangeError: Error #1506: The specified range is invalid. 
at cmodule.aircall::FSM_imalloc$/start() 
at cmodule.aircall::FSM_pubrealloc/work() 
at cmodule.aircall::CRunner/work() 
at Function/<anonymous>() 
at flash.utils::Timer/_timerDispatch() 
at flash.utils::Timer/tick() 

my code is as follows:

private var im:img; 
private var jpgStream:ByteArray; 
private var jpeglib:Object; 
private var jpeginit:CLibInit = new CLibInit(); // get library 

public function save_image(_im:img, pg:Number):void 
{ 
     var bm:BitmapData = Bitmap(_im.getChildAt(0)).bitmapData; 
     im = _im; 

     var imgData:ByteArray = bm.getPixels(bm.rect); 
     jpgStream = new ByteArray(); 
     imgData.position = 0; 

     trace(bm == null); 
     var jpegQuality:Number = 40; 

     if (!jpeglib) { 
          jpeglib=jpeginit.init(); 
     } 
     jpeglib.encodeAsync(encodeComplete, imgData, jpgStream, bm.width, bm.height, jpegQuality); 
} 

private function encodeComplete(e:Event):void { 
     trace("Encoding complete"); 

     file = File.documentsDirectory.resolvePath("Pic-A-Note/" + albumName + "/object_layer_" + im.name + ".pn"); 
     fs.open(file, FileMode.WRITE); 
     fs.writeBytes(jpgStream,0); 
     fs.close(); 
}

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

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

发布评论

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

评论(2

请止步禁区 2024-12-12 09:19:50

问题是您正在初始化 CLibInit 两次。我创建了一个自定义类来使用 jpegencoder.swc 透明地处理 jpg 的编码,就像您对本机类所做的那样。

public class JPGAlchemyEncoder {

    private static var alchemyWrapper:Object;
    private var quality:Number;

    public function JPGAlchemyEncoder(quality:Number) {
        this.quality = quality;
        if (!alchemyWrapper){
            var loader:CLibInit = new CLibInit;
            alchemyWrapper = loader.init();
        }
    }

    public function encode(bitmapData:BitmapData):ByteArray{
        var data: ByteArray = bitmapData.clone().getPixels( bitmapData.rect );
        data.position = 0;
        return alchemyWrapper.write_jpeg_file(data, bitmapData.width, bitmapData.height, 3, 2, quality);
    }

    public function encodeAsync(bitmapData:BitmapData, completeHandler:Function):void{
        var encodedData:ByteArray = new ByteArray();
        var data: ByteArray = bitmapData.clone().getPixels(bitmapData.rect);
        data.position = 0;
        var encodeComplete:Function = function():void{
            completeHandler(encodedData);
        };
        alchemyWrapper.encodeAsync(encodeComplete, data, encodedData, bitmapData.width, bitmapData.height, quality);
    }
}
}

检查构造函数如何处理静态 CLib。这样您就可以根据需要启动任意数量的 JPGAlchemyEncoder,但 CLib 将仅初始化一次,从而解决您的问题。

The problem is that you are initializing the CLibInit twice. I've created a custom class to handle encode of jpg's transparently using jpegencoder.swc, like you do with the native class.

public class JPGAlchemyEncoder {

    private static var alchemyWrapper:Object;
    private var quality:Number;

    public function JPGAlchemyEncoder(quality:Number) {
        this.quality = quality;
        if (!alchemyWrapper){
            var loader:CLibInit = new CLibInit;
            alchemyWrapper = loader.init();
        }
    }

    public function encode(bitmapData:BitmapData):ByteArray{
        var data: ByteArray = bitmapData.clone().getPixels( bitmapData.rect );
        data.position = 0;
        return alchemyWrapper.write_jpeg_file(data, bitmapData.width, bitmapData.height, 3, 2, quality);
    }

    public function encodeAsync(bitmapData:BitmapData, completeHandler:Function):void{
        var encodedData:ByteArray = new ByteArray();
        var data: ByteArray = bitmapData.clone().getPixels(bitmapData.rect);
        data.position = 0;
        var encodeComplete:Function = function():void{
            completeHandler(encodedData);
        };
        alchemyWrapper.encodeAsync(encodeComplete, data, encodedData, bitmapData.width, bitmapData.height, quality);
    }
}
}

Check how the constructor deal with the static CLib. This way you can start as many JPGAlchemyEncoder's as you want but the CLib will be initialized only once, solving your problem.

神仙妹妹 2024-12-12 09:19:50

没有使用过那个 swc,但是 AS3Corelib 中的非 alchemy jpeg 编码器也可以完成这项工作(没有任何错误,我可能会补充)
http://code.google.com/p/as3corelib/

Haven't used that swc, but the non-alchemy jpeg encoder in AS3Corelib will do the job just as well (without any errors, I might add)
http://code.google.com/p/as3corelib/

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