I have a Silverlight 3 project with something like this:
Instead of creating a MSBuild task you can also create a Custom tool and specify this in Custom Tool in properties of your image file.
"a custom tool will transform a file at design time and will place the output of the transformation into another file"
e.g. DataSet. it has its own transformation tool through which we get a class to use in our application.
the advantage of this approach is you can use the generated file at design time as well.
as sample implementation can be found at http://www.drewnoakes.com/snippets/WritingACustomCodeGeneratorToolForVisualStudio/