Quantcast
Channel: Adobe Community : Popular Discussions - Archived Discussions
Viewing all articles
Browse latest Browse all 21156

Help With Loading an Image In AIR

$
0
0

I need to load an image (GIF) with AIR using File and FileStream, but can't figure out how to do it. I need to load the image into a Bitmap or BitmapData object, so I can't use the loader class. Here's what I have so far:

import flash.display.*;
import flash.events.*;
import flash.filesytem.*;
import flash.net.FileFilter;
import flash.utils.ByteArray;
import flash.geom.Rectangle;

var file:File = File.documentsDirectory;
var myImage:BitmapData;
var myFilter:FileFilter = new FileFilter("GIF Image","*.gif");
file.addEventListener(Event.SELECT,loadImage);
file.browseForOpen("Open",[myFilter]);

function loadImage(e:Event):void{
var stream:FileStream = new FileStream();
stream.open(file,FileMode.READ);
var bytes:ByteArray = new ByteArray();
stream.readBytes(bytes);
stream.close();
//By the way, this image is a special format and will always be 160 by 160 pixels.
myImage = new BitmapData(160,160);
bytes.position = 0;
myImage.setPixels(new Rectangle(0,0,160,160),bytes);
addChild(new Bitmap(myImage));
}

However, this never works. I always get this error:

Error #2030: End of file was encountered.

I don't quite understand why. Help would be much appreciated.


Viewing all articles
Browse latest Browse all 21156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>