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.
My transformation started with ThoughtFaqtory nearly a year ago and before that I was a new vehicle salesperson with a propensity for pyrotechnics. . . like blowing things up! With a burning desire to be in the IT industry, but without an opportunity to make the move to becoming a software developer, I was up the river without a paddle! A couple of years ago the motor industry experienced a downward trend in sales, realizing that this maybe a blessing in disguise, a Plan B was necessary. While sitting on the sales floor watching tumble weeds roll past, I embarked on teaching myself Java, as I was more than willing to invest that time in my future. By the end of last year I felt confident enough to find myself an employer that would be willing to take me on. ThoughtFaqtory was on my radar, through a newspaper editorial, and contacted Simon and Phil Barber. They offered me this huge opportunity to learn from within their company and then spent the next 6 months on a rigorous training program using Flex.
So the former sales person was morphed into a developer, but I must share a little secret – my father was a programmer for Siemens, so let’s say it’s in the blood. ThoughtFaqtory offered me some time to research a technology of my choice and was given the opportunity to post this blog. Two weeks was invested learning how to use Pixel Bender; there are numerous amounts of resources that you can look at if you want to learn how to use it. Keith Peters had a fantastic chapter on Pixel Bender in his book “Advanced ActionScript Animation” which was a great help and also adapted one of his examples to my needs in this example. Also available was some excellent info from Lee Brimelow and his tutorials on www.gotoandlearn.com. A shout also goes out to Jonathan Hart who had an awesome example of RGB sine distortion on http://synja.com, which was adapted for this presentation.
This article does not cover the actual Pixel Bender code but shows you how to import the filters in Flex and create a small animation using 4 filters that were created in Pixel Bender. I implemented a base class that each of my custom filters could extend. This would give them the ability to dispatch an event when any of the properties on the filter have been updated. My application could listen for this event on each of the filters and reapply them to the image and update the display.
An animation class was created that would control this and allow various properties to be animated. I do realize that Flash actually provides such classes already but wanted to discover this unknown territory for myself and see how well I would do in solving any obstacles that were cast in my path. It was another learning curve and an enjoyable one. The AnimateFilter class takes an array of Properties on the filter that should be animated. Provision was made for reversing the animation, setting a delay to start the animation and also setting a delay to reverse the animation. The AnimateFilter takes a target, which is the filter that contains the properties to be animated. This can be set up in MXML.
The resulting image has the filters applied and you can see the result when you move your mouse over the image. Four filters have been attached to the image and have an animation set up for each of the filters, which plays on the mouseOver event. The combination of all 4 filters gives an unusual effect. . . at least I think so. CHECK OUT MY EXAMPLE ABOVE.
So there you have it. I am very proud of how far I have come from being a salesperson less than a year ago to where I am now. I would never have been able to absorb this amount of information without the help of all the awesome staff at ThoughtFaqtory. There is a realization though that with this kind of opportunity comes the responsibility to apply myself and work hard to achieve my goals. But in the meantime, I’m loving every minute of it and still blowing things up . . . only kidding.
Last week Friday, the 11th September, our first article for InsideRIA went live. It is entitled “Custom Sortable List Component using Flex 4″ and introduces the reader to a few new concepts found in the Flex 4 SDK.
Below is an excerpt from the article:
“Recently, I decided to get my hands dirty with the latest build of Flex 4 SDK and Flash Builder 4. The new IDE has a lot of really exciting new features that will save developers a lot of time. The features that excite me the most are the new Spark components and skinning capabilities in the new SDK. Towards the beginning of the year I had read through the first few drafts of the new Spark component architecture, the style changes and how easy it is to skin components. Lots of things have changed since then, so I decided to refresh my memory and build a simple component to test my knowledge.
Behold the SortableList component.”
A few concepts in the article include Spark components, skinning and basic custom component development.
This is one of many articles we will be writing in the next few months.
Also, thank you to Rich Tretola and O’Reilly for giving us this opportunity.

United States of America
Having just returned from your magnificent country and gathered our breath, it was great to reflect on the truly amazing time that we had in America, the challenges ahead and the people we met on our travels.
Let me tell you – you sure have one hell of a country.
Adjectives like superb, wonderful, splendid, brilliant, outstanding, superlative spring to mind and I’m just describing your restaurants in Indianapolis, New York and Boston.
But one thing permeates throughout the people we encountered, that’s respect and a love of hard work, nothing is too much trouble.
“Wanna go to the Indianapolis Speedway” up steps David Bigelow of Nitro-LM and we were transported there. What’s more we even drove around it, me at the wheel, pretty awesome and a dream come true. Thank you David and your sales team at Nitro-LM.
It was great meeting you and the Flex community at the 360Flex Conference and having a chance to talk, share life experiences and ideas as well. Two days traveling from Cape Town, South Africa made it all worthwhile. The guys at 360 Conferences Tom Ortega and John Wilker performed superhuman feats of endurance, organization, PR skills and still managed to keep their sanity as well as a smile, even though sleep deprivation must have been paramount in their mindsets. We thought the conference was well worth the price of admission if you take cognizance of what was on offer.
Knowledge was on tap, smart ways to utilize the source code, opportunities to educate yourself or your team. With presentation names like: Clients are stupid and other observations, The great mash up, The art of project management in large scale Flex projects, The business of a team instead of an army, The business side of Flex, The business side of selling Flex/AIR applications and Setting up your corporate library. There was something for all. Then there was the cool shit aka Doug McCune who blew us away with topics like: Steganography, Head Tracking Targets, Safe Sexting and Augmented reality demo with fake chests. . . AWESOME. You see something for everyone!
Balance, subjectivity and self education were the keys in all aspects of the other presentations whether it was design, development or business related subjects. If I was a manager, it would be a no brainer not to attend. I would be scolding myself for not sending any representation and ensuring that I send my staff next year. We did hit Rock Bottom. . . the Brewery, every night just to clear the cobwebs and hang out! Tom and John must be congratulated for their yeomen feats in presenting an exceptional conference in Indianapolis. Congrats – Great Job!
Leaving Indianapolis and onto New York, we were made African brothers by our Nigerian taxi driver! A visit to the new Yankee Stadium; I was never a YANKEE FAN! But now I’m a full convert. Adjectives abound now – well only one. . . a magnificently managed extravaganza was on offer and we grabbed it with both hands, so New York. . . even Paul Simon was there for us on Memorial Weekend. The rest of weekend was spent walking around the city visiting Starbucks, the Apple store 5th Avenue. . . wandering through Central Park, it’s so big – people getting married, picnicking and playing ball. Looking out for the DAKOTA building where John Lennon lived before his untimely death in 1980. Visiting Federal Hall where New York owes so much of its history including the inauguration of George Washington, the first President of the United States. Then, finally a visit to Ground Zero and the Empire State Building. Meeting more interesting people along the way.
Picking up a hire car or truck or SUV or whatever they’ve got. . . and driving on the wrong side of the road to Boston, through Connecticut, Massachusetts, Providence and finally to Boston. Taking in the city, the historic Faneuil Hall Marketplace, the “Gateway to Boston” since 1026, Boston Harbour and surrounds, we bumped into Adam Sandler and he didn’t even recognize we were from South Africa! We managed to take a drive out to Harvard University your private university in Cambridge, Massachusetts, and a member of the Ivy League. Founded in 1636 by the colonial Massachusetts legislature, Harvard is the oldest institution of higher learning in the United States. It is also the first and oldest corporation in North America. Harvard University is made up of ten schools and the closest most of us will get to achieving a degree of that status.
Our visit to America has made us realize the extent to which both our countries face in dealing with this global recession. Can we rise to the challenge? Sure we can. . . by working together, learning from one another and supporting each other, we can create solutions using our expertise and the Adobe Flex/AIR software tools at our disposal, to enable leaders and captains of our respective countries, industries and commerce, to more easily and effectively manage our economies and their bottom lines, so that we don’t return to this Economic Nirvana.
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