Search This Blog

code monkey

Posts

Pinta wouldn't exist today without the amazing code from the previously open source Paint.NET. Now we've decided to pay it forward and make that same code available for other developers to easily use in their applications.

To accomplish this, we've extracted the code for all of Pinta's effects into a graphics toolkit agnostic library called Pinta.ImageManipulation and posted it up on NuGet for easy use. This includes over 35 multi-threaded effects exposed as cancelable Tasks.

The core of Pinta.ImageManipulation is graphics toolkit agnostic and only works on arrays of BGRA bytes, but we've also included wrappers for System.Drawing (GDI+) and Cairo (GTK+).

Now that you've got all those great new holiday photos, let's see how to apply an effect to them in 5 lines of code.

Create a new project, bring up the NuGet dialog, and search for Pinta:

Thanks to Scott Hanselman's recent article on .NET's support for Portable Class Libraries (PCLs), there has been some renewed interested in using them for Mono for Android.

If you try to add a reference to a compiled PCL assembly, things should work, as VS simply checks that the version of mscorlib.dll referenced is the same as the MFA project (2.0.5). However, if you try to add a reference to a PCL project, you get this nasty dialog box:

The bad news is we don't ship any tooling for supporting these out of the box yet. The good news is it's trivial to do it yourself!

The portable libraries are installed in .NET's Reference Assemblies folder, which is here:

As a tools guy, I've been fascinated with Roslyn ever since Microsoft previewed it. It looks like it provides lots of power for tools to consume. Now that the first CTP is out, I spent some time over the weekend playing with it.

The first thing it gives you access to is parsing source code, giving you an object model you can play with, and then letting you spit the modified source code back out. Reading source code in is easy:var source_text = File.ReadAllText ("input.txt");
var tree = SyntaxTree.ParseCompilationUnit(source_text);
var root = (CompilationUnitSyntax)tree.Root;
Now we have an object model we can play with. We can search through the model for specific tokens and replace them with new ones, like this:// Replace "Hello World!" with "Goodbye World!"
var output = root.GetFirstToken (p => p.Kind == SyntaxKind.StringLiteralToken);
var new_output = Syntax.StringLiteralToken ("\"Goodbye World!\"", "Goodbye World!…

About 4 months ago, I worked on porting some of the Android SDK samples to run on MonoDroid. It was a soul-crushing failure. Every line of code I wrote exposed a new bug in MonoDroid which I had to wait until it got fixed to continue. Eventually I gave up on doing anything more than the absolutely trivial Hello World.

What a different story things are today!

I dusted off my unfinished Snake port, and it now works without modification.

Since I did it so long ago, there was no telling what magic I had in there to make it work on MonoDroid, so I ported another one from scratch. I grabbed the hardest sample I think they have: JetBoy. It's basically a fast-paced, Guitar Hero-esque game where you have to fire your laser to the music as each asteroid passes across the beat line.

After an afternoon of literal translation to C# (over 1k LOC), I fixed up the few Java porting issues like anonymous classes and nested classes accessing the parent class's private variables, and it *just wor…