So I’m getting back to trying to learn AIR. I had originally written a few small apps way back when it was in alpha, so now I’m learning the release version. It’s surprisingly simple. My goal with this app was to play with the saving of bitmaps to the hard drive, and it turned out to only require 8 or so lines of code.
1 2 | var bd:BitmapData = new BitmapData(targetCanvas.width, targetCanvas.height, false); bd.draw(targetCanvas); |
1 2 | var jpgEncoder:JPEGEncoder = new JPEGEncoder(75); var imgByteArray:ByteArray = jpgEncoder.encode(bd); |
1 | var fs:FileStream = new FileStream(); |
1 2 3 4 5 6 7 8 9 | try{ fs.open(file, FileMode.WRITE); fs.writeBytes(imgByteArray); fs.close(); }catch(e:Error){ Alert.show("Error saving file :( : " + e.message); return; } Alert.show("File Saved."); |
I’m also using the AS3 Flickr API from adobe, which is another thing I haven’t played with yet. I’m finding the documentation for the flickr api to be slightly less than spectacular, it doesn’t seem to actually match up with how the API works, but I did manage to get a search of creative commons licensed photos working.
Anyway, check it out. It’s still in progress, so please let me know if you find any bugs, or just have suggestions for improvement.