Recently in the picture Upload tool, so I met filereference open local picture crash problem, search the next solution, get the following article:
Prior to Flash 9, the ability to preview local pictures with flash 9,flash was not possible. Flash 10 adds the Filereference.load method to make the local picture preview possible. Use process:
Filereference.browse (), Filereference.load (), and Loader.loadbytes (filereference.data), use skip.
There is a problem with this use process,
When you encounter a large picture, the local preview will have a more serious performance problem, preview a 3.5M picture, memory up to 60M, preview 15 3M around the size of the picture, memory soared to 500M, may cause user browser crash.
http://myadobe.ro/2008/11/24/filereference-the-end-of-upload-tyranny-guest-post-by-andrei-rosca/
Gives the solution.
The general idea is that after the loader is loaded into the image data, do the following:
Make the image of PX in height
var scale:number=50/loader.height;
And actually resize it
Loader.width*=scale;
Loader.height*=scale;
Loader.width=math.round (Loader.width);
Loader.height=math.round (Loader.height);
Use a container so we don ' t need a matrix in Bitmapdata.draw
var container:sprite=new Sprite ();
Container.addchild (loader);
Take the snapshot
var bmpdata:bitmapdata=new BitmapData (container.width,container.height);
Bmpdata.draw (container);
var bmp:bitmap=new Bitmap (Bmpdata);
In this way, the equivalent of the picture scaling, get the bitmap data, converted to bitmap objects, so that only to add bitmap object to the container to achieve a picture preview.
The above method is only valid when Flash Player itself is running, and you need to do an action on the browser to load the SWF preview local Picture:
(Loader.contentLoaderInfo.content as Bitmap). Bitmapdata.dispose ();
Remove the BitmapData reference from the original in memory
Loader.unload ();
But this method does not completely solve the problem, after observing that the first time you open the browser and open the first big picture must crash, then guess is due to flash player memory space is not enough, The Filereference load method does not get enough memory space after loading the file to cause a crash.
So my approach is to add the following code at the beginning of the program:
(new BitmapData). Dispose ();
System.GC ();
Create a bitmap that is large enough to open Flash Player memory.
Practice has proved that this method works!
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/tools/