1. Target: Save the byte stream image on the Android local path, such as "/data/mypppd/",
File = File.documentsDirectory.resolvePath ("/data/mypppd/" +countpoint+ ". jpg"); New FileStream (); Filestream.open (file, filemode.write); Filestream.writebytes (Bytes[countpoint]); Filestream.close ();
2. Target: Read the picture file display from the Android local directory (for example, to display the ad image)
If you read the picture from "/data/mypppd/", do not know in advance that there are several files in the directory, provide a solution to initialize an array, where the length is set to 7, the display of the loop in turn, encountered a non-existent direct jump to the next loop, so that you can display 0-7 pictures in turn any of the case.
A. Read the picture file locally (saved in urlreq and can be accessed via load)
New Array (); New Array (); for (Var j:int = 0; J < 7; J + +) { = "/data/mypppd/" + (j+1) + ". jpg"; = File.documentsDirectory.resolvePath (path); New urlrequest (File[j].url); }
B. Display pictures
protectedfunction Myload ():void{IMG1=NewImage; Load=NewLoader; //Error event when a listener file does not existLoad.contentLoaderInfo.addEventListener (Ioerrorevent.io_error, Loaderrorhandler); //if (urlreq[index]! = null)//loading pictures into loadload.load (Urlreq[index]); //global variable index, control picture sequence number, initialize to 0index++; if(Index >= 7) Index= 0; //Picture Mount completion eventLoad.contentLoaderInfo.addEventListener (Event.complete, imgloaded);} //continue calling Myload () when the picture file does not exist, looking for the next onePrivatefunction Loaderrorhandler (event:ioerrorevent):void{trace (event.tostring ()); if(Index >= 7) Index= 0; Myload ();} //calling a function after loading endsPrivatefunction imgloaded (e:event):void{ //Displays the loaded picture in an image control named pic.Pic.source=load.content; //VisibleImage.visible =true; }