cameron314 / PNGEncoder2

A better PNG encoder for Flash
97 stars 10 forks source link

Error: Error #1000: The system is out of memory. at flash.utils::ByteArray/readBytes() at _PNGEncoder2::PNGEncoder2Impl$/writeIDATChunk() at _PNGEncoder2::PNGEncoder2Impl/onEnterFrame() #7

Open matrix3d opened 7 years ago

matrix3d commented 7 years ago

Error: Error #1000: The system is out of memory. at flash.utils::ByteArray/readBytes() at _PNGEncoder2::PNGEncoder2Impl$/writeIDATChunk() at _PNGEncoder2::PNGEncoder2Impl/onEnterFrame()

cameron314 commented 7 years ago

Yes? How big is the bitmap you're trying to compress? Have you tried a profiler to see where the memory is going? More details, please! :-)

matrix3d commented 7 years ago

it is this https://github.com/cameron314/PNGEncoder2/issues/5 work good for me.

but is it there a decoder from file?

cameron314 commented 7 years ago

Great, I'm glad the IDataOutput version works for you.

Yes, in the same gh-IDataOutput branch, there's a decode method that accepts an IDataInput. It's synchronous and only works on PNGs encoded with PNGEncoder2, though.

matrix3d commented 7 years ago

my code.

chaifenfile = fs[0] as File;
            var fs2:FileStream = new FileStream;
            fs2.open(chaifenfile, FileMode.READ);
            var bmd:BitmapData = PNGEncoder2.decode(fs2);
            trace(bmd.width, bmd.height);

and get Error #1000: The system is out of memory.

matrix3d commented 7 years ago

and use flash loader,also out of memory.

var chaifenloader:Loader = new Loader;
            chaifenloader.contentLoaderInfo.addEventListener(Event.COMPLETE, chaifenloader_complete);
            chaifenloader.load(new URLRequest(chaifenfile.url));
matrix3d commented 7 years ago

i just want split the big image 2 a lot of small images. so can i just get the png width,and height from a file? and get the sub bitmapdata from rect?

cameron314 commented 7 years ago

Hmm. Looks like the bitmap really is just too big to load in flash (what is its width/height?).

You can get the width and height from the header of the PNG file, but the pixel data is pre-processed, compressed, and split up across several "IDAT" chunks in the file, which means it's impossible to access an arbitrary section of the image given just the coordinates (the whole file has to be scanned, decompressed, and post-processed from start to finish before any pixels can be accessed).

Can you split the big image into smaller images when you save it instead of when you load it?

matrix3d commented 7 years ago

the image not too big.just 275m.15616x8960px

cameron314 commented 7 years ago

Ah. That's a big image :-)

When loading a PNG, the bitmap ends up being in memory twice (since there's the raw uncompressed memory from the decode step plus the Flash bitmap object created from that raw memory, before the raw memory can be deallocated) plus the compressed version too (which at least isn't loaded all at once into memory in my IDataInput version, but still).

With transparency, there's 4 bytes per pixel (of uncompressed raw pixel data), for a total minimum memory requirement of 533MB*2 = ~1GB. Without transparency, there's only 3 bytes per pixel required, which comes to 400MB*2 = 800MB. So, it's understandable that flash is running out of memory.