
If you are a Flex developer or wanting to learn Flex, i highly recommend you look at Adobe’s video training course called Flex 4 beta in a Week.
The course is broken up over 5 days as follows:
Day 1 – Exploring the basic, Introducing object-orientated programming and Understanding components and layouts
Day 2 – Handling events, Validating and formatting data, Navigating application content and Animating components and states
Day 3 – Controlling text display, Controlling visual display and CSS and Skinning Spark components
Day 4 – Extending events, Accessing remote data and Creating a typed data model
Day 5 – Displaying data with the DataGroup container, Displaying Data with the DataGrid control and Deploying Flex and AIR Applications
Seasoned Flex developers may only find some of these areas useful, such as the Skinning Spark components and Displaying data with the DataGroup container (Coming soon).
At ThoughtFaqtory we are continually encouraged to think outside of the box when challenges are presented. A challenge was set recently by a pretty innocuous requirement from one of our clients.
This project required me to implement functionality that would allow the end user to export groups of images to PDF. The PDF needed to be high quality, 300 ppi (pixels per inch). After some searching I came across the AlivePDF website which appeared to be perfect for my requirements. Initially after using AlivePDF to generate a few PDFs, I couldn’t believe how easy it was to use and I thought that I had found Utopia. My joy however was short lived after the following error message was received:
AlivePDF had no alpha channel support for PNGs and the PNG encoder provided by Adobe always returns a PNG with an alpha channel. Even if you turned off the transparency you will get back a 32 bit ARGB PNG.
I continued searching for someone who had a method of successfully removing the alpha channel but my search proved fruitless. Hence I decided to do my own research into PNGs and found the following:
A valid PNG consists of:
PNG signature
IHDR chunk (only one)
IDAT chunk (one or more)
IEND chunk (only one)
The PNG signature:
89 50 4E 47 0D 0A 1A 0A.
The IHDR image header:
| Width: | 4 bytes |
| Height: | 4 bytes |
| Bit depth: | 1 byte |
| Colour type: | 1 byte |
| Compression method: | 1 byte |
| Filter method: | 1 byte |
| Interlace method: | 1 byte |
The IDAT chunks contain the image data.
The IEND chunk marks the end of the PNG.
The colour type under the IHDR chunk needs to be mentioned here as that is where the image type is defined.
| Image type | Colour type |
| Greyscale | 0 |
| True colour | 2 |
| Indexed colour | 3 |
| Grey scale with alpha | 4 |
| True colour with alpha | 6 |
After familiarizing myself with PNGs, I revisited Adobe’s PNGEncoder.as class again and eventually managed to make certain changes that allowed the removal of the alpha channel all together.
After all the research this ended up being a lot easier than I had originally thought, all that I needed to do was change the colour type and extract the RGB values. Adobe’s colour type was 6 (True colour with alpha) I changed it to 2 (True colour only). Next I needed to isolate and extract the RGB values, this was done with a bitwise right shift operation and a bitwise AND operation.
// Build IHDR chunk var IHDR:ByteArray = new ByteArray(); IHDR.writeInt(w); IHDR.writeInt(h); IHDR.writeUnsignedInt(0x08020000); // True colour (no alpha) IHDR.writeByte(0); writeChunk(png, 0x49484452, IHDR); // Isolate RGB values for (var j:int = 0; j < w; j++) { p = img.getPixel(j, i); IDAT.writeByte(p >> 16 & 0xFF); IDAT.writeByte(p >> 8 & 0xFF); IDAT.writeByte(p & 0xFF); }
The changes implemented resulted in the removal of the Alpha channel which allowed me to successfully embedded the encoded PNG image into a PDF with AlivePDF. This was the first of many problems I had working with PDFs, maybe you will get to read about the others in the not too distant future. Attached below is a sample application that will embed a PNG into a PDF.
One of my colleagues at ThoughtFaqtory found this nice resource “Learn to Use Flash Catalyst” on Adobe Labs web site.
I have listed all the tutorials, videos and screencasts below.
Get Started
Learn about Flash Catalyst
Start Building Your First Flash Catalyst Application
Get Better
Explore Flash Catalyst Workflows
Work with Flash Catalyst
Learn from the Community