如何在AS3上从巨大的BitmapData复制Pixels()?
我需要在 AS3 上加载一个非常大的图像(当前大小为 8192x8192)。我知道它不符合 Flash 对绘制到屏幕或创建该大小的 BitmapData 施加的任何限制。我只想加载图像,这样我就可以在这里或那里复制它的某些部分。
问题是,我加载该大小的 .jpg 文件没有任何问题。我的 Loader 对象可以正确识别大小。我像这样加载它:
mImageLoader = new Loader();
var anImageURLRequest:URLRequest = new URLRequest("8192x8192.jpg");
mImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
mImageLoader.load(anImageURLRequest);
然后,在 onComplete 方法上,我尝试执行以下操作:
Bitmap(mImageLoader.content).bitmapData.getPixel(1000, 1000);
但我遇到了 #2015“Invalid BitmapData”错误,该错误通常是为太大的 BitmapDatas 保留的。如果我尝试执行 copyPixels() ,也会发生该错误,这正是我需要做的。
是否有任何解决方法可以使用,以便我可以从 AS3 上这么大的图像中获取数据?
I need to load a very big image on AS3 (currently sized at 8192x8192). I am aware that it does not fit any of the limits imposed by Flash regarding drawing to screen or creating a BitmapData of that size. I just want to load the image so I can copyPixels() some parts of it here and there.
The thing is, I'm loading the .jpg file of that size with no problems. The size is recognized correctly from my Loader object. I load it like this:
mImageLoader = new Loader();
var anImageURLRequest:URLRequest = new URLRequest("8192x8192.jpg");
mImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
mImageLoader.load(anImageURLRequest);
Then, on the onComplete method, I try to do this:
Bitmap(mImageLoader.content).bitmapData.getPixel(1000, 1000);
But I am greeted with the #2015 "Invalid BitmapData" error usually reserved for BitmapDatas that are too big. The error also happens if I try to do a copyPixels(), which is what I need to do.
Is there any workaround I can use so I can get data from an image this big on AS3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,无法使用标准 BitMap 类对 AS3/FlashPlayer 执行此操作。
但是,您可以尝试使用 bytearray.org 的 JPEG 解码器将文件作为原始 ByteArray 读取,然后确定您需要的像素。 - 我不能保证它可以与 8192x8192px 图像一起使用,但值得一试,因为它不依赖于 Flash 显示系统。
如果您确实使用此方法,请记住像素存储在单个 Vector 中,因此您需要执行以下操作:
要获取所需的像素。
Unfortunately there's no way to do this with AS3/FlashPlayer using the standard BitMap classes.
However, you could try bytearray.org's JPEG Decoder to read the file as a raw ByteArray and then determine the pixels you require like that. - I can't guarantee that it'll work with and 8192x8192px image, but it's worth a try, since it's not reliant on the Flash display system.
If you do use this method, remember that the pixels are stored in a single Vector so you'll need to do something like:
To get the pixel you want.
从 AIR 3 和 Flash Player 11 开始,BitmapData 对象的大小限制已被取消。位图的最大大小现在取决于操作系统。
来源
Starting with AIR 3 and Flash Player 11, the size limits for a BitmapData object have been removed. The maximum size of a bitmap is now dependent on the operating system.
Source