Hmm. That's not a very good example for the OP to follow. It won't handle all image file extensions, check for failure in opening the stream, choose the correct image size, render any subcomponents, or choose between RGB/ARGB formats depending on whether the component is opaque.
What you want is something like this:
static bool writeComponentImageToFile (const File& file, Component& comp, Rectangle<int> subArea)
if (ImageFileFormat* format = ImageFileFormat::findImageFormatForFileExtension (file))
FileOutputStream out (file);
return format->writeImageToStream (comp.createComponentSnapshot (subArea), out);
I've not tried compiling this, but you get the gist..