Fork me on GitHub

Instead of working with the object model directly, you can use the fluent API. The fluent API allows you to build up an image, including layers and filters, in fewer lines of code. To get started, create an instance of CompositionBuilder:

CompositionBuilder builder = new CompositionBuilder();

You can set various properties on the composition:

CompositionBuilder builder = new CompositionBuilder()
	.Width(300).Height(200)
	.ImageFormat(DynamicImageFormat.Png)
	.FillBackgroundColor(Colors.Red);

You can add layers:

CompositionBuilder builder = new CompositionBuilder()
	.WithLayer(LayerBuilder.Image.SourceFileName("tulips.jpg").PaddingLeft(10))
	.WithLayer(LayerBuilder.Text.Text("Hello World").Width(200));

You can add filters:

CompositionBuilder builder = new CompositionBuilder()
	.WithLayer(LayerBuilder.Image.SourceFileName("tulips.jpg").PaddingLeft(10)
		.WithFilter(FilterBuilder.AdjustBrightness.Level(50))
		.WithFilter(FilterBuilder.Crop.To(400, 300)))
	.WithLayer(LayerBuilder.Text.Text("Hello World").Width(200))
	.WithGlobalFilter(FilterBuilder.Resize.To(100, 100));

Finally, you can get the resulting image in a number of ways:

string url = builder.Url; // Returns the URL to a cached image.
BitmapSource bitmap = builder.GetImage(); // Returns a BitmapSource object.
builder.SaveTo("image.jpg"); // Saves the image to disk.