jpegencoder.swc 来自 http://last.instinct.se/graphics-and-effects/using-the-fast-asynchronous-alchemy-jpeg-encoder-in-flash/640
有人在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您正在初始化 CLibInit 两次。我创建了一个自定义类来使用 jpegencoder.swc 透明地处理 jpg 的编码,就像您对本机类所做的那样。
检查构造函数如何处理静态 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.
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.
没有使用过那个 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/