Web Snapshot - a simple Apollo Application. 7

Posted by Daniel Wanja Thu, 05 Apr 2007 05:16:00 GMT

This simple Apollo Application takes 200×150 thumbnails of a Web page.

UPDATE: See Web Snapshot – a simple Adobe AIR application

20070404_WebSnapshot.jpg

1) Enter the URL of the page you want to “Snap”. 2) Click the Thumbnail 3) A file dialog opens and asks for the File to save.

Download it now: WebSnapshot0.1.air (right click and ‘Download Linked File’)

It uses the new HTMLControl that Apollo provides, which behind the scene is a full fledged web browser based on KTHML. Check out an extract of the source code:

//1. Load the page (asynchronously)
var html:HTMLControl = new HTMLControl();
html.width = 400;
html.height = 300;
html.load(new URLRequest(url));

//2. Draw and scale the rendered html into a bitmap
var snapshot:BitmapData = new BitmapData(200, 150);                
var matrix:Matrix = new Matrix();
var scaleX:Number = 0.5;
var scaleY:Number = 0.5;
matrix.scale(scaleX, scaleY);
snapshot.draw(htmlContent, matrix);

//3. Save as JPEG
var jpegEnc:JPEGEncoder = new JPEGEncoder(75); 
var jpegData:ByteArray = jpegEnc.encode(snapshot);        
var stream:FileStream = new FileStream() 
stream.open(file, FileMode.WRITE); 
stream.writeBytes(jpegData);
stream.close(); 

I found the JPEGEncoder here.

And Daniel Dura had a trick to use a native save windows.

Note I need to try this application on Windows…I’ll do that tomorrow.

Enjoy! Daniel

Update:I quickly tried on Windows XP and the save doesn’t seem to work. Let me know how it works for you. Thanks.

UPDATE: See Web Snapshot – a simple Adobe AIR application

Comments

Leave a response

  1. Lee Thu, 05 Apr 2007 07:04:44 GMT

    Very cool! When can I use it on Linux? :)

  2. Daniel Wanja Thu, 05 Apr 2007 14:09:25 GMT

    Apollo will be supported on Linux but I believe only once Adobe releases version 1. Currently there is an Apollo run time for Windows and OSX.

  3. Daniel Wanja Thu, 05 Apr 2007 15:52:35 GMT

    I just saw that Web Snapshot was linked from Apollo:Applications page. There I saw that I wasn’t first to the game, there is another similar application Grabit that’s looks pretty good.

  4. Sean Voisen Tue, 10 Apr 2007 20:54:07 GMT

    Sweet.

    P.S., if you wrap that wide screenshot image in a container div with overflow: hidden, it won’t screw up your sidebar :)

  5. Daniel Wanja Tue, 10 Apr 2007 23:35:57 GMT

    Thanks Sean. PS: wrapped the image…looks better.

  6. Journalist Tue, 17 Apr 2007 18:32:11 GMT

    Did you make it work in Windows? I don’t have any other OS :(

  7. Daniel Wanja Tue, 17 Apr 2007 18:40:31 GMT

    Not yet. But now that you’ve put the pressure on, I’ll have to tackle it soon;-) I need to see if the issue is in my code or if Daniel Dura’s trick just doesn’t work on Windows. The issue is that the current version of Apollo doesn’t provide a native save file Dialog without using the trick. If I don’t find a way to make the “trick” work on Windows, I’ll create a simple custom Apollo Save File dialog. Little bit more work, but I did something similar with the RailsLogVisualizer.

Comments