Offline Maps: oops, fixed small/severe bug – version 1.3.1

I recently released the 1.3.0 version of my Offline Maps application. This weekend I started preparing for our holidays and noticed several crashes: there was an error in the tile caching.

The error affeced only the desktop application and is now fixed so everything should work fine now. The corrected version is now version 1.3.1

And what do we learn from this: test thouroughly !!! I urgently need to setup some automated testing for this application. It started of to be a quick application to download some tiles from Google Maps so I thought I wouldn’t need any testing but it is quickly expanding with other functionality.

Visit the Offline Maps page to download it.


For once and for all: Graphics.DrawImage

During development of the last update of my Offline Maps application I had been struggling with the DrawImage method of the Graphics class in the System.Drawin namespace

All in all it’s not that difficult. You just need to read the documentation very carefully and understand the meaning of the words.

Just to share what I learned, here’s a little tutorial on the method, more specifically the version that accepts two rectangles: DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)

Create the source bitmap:

Bitmap sourceBmp = 
   new Bitmap(113, 113, PixelFormat.Format24bppRgb);
// perform some initalization on the bitmap ...

Which gives us the following:

In this bitmap, we define a source rectangle. The coordinates of the rectangle are relative to the origin of the bitmap:

Rectangle sourceRect = new Rectangle(21, 64, 157, 86);

This results in following rectangle, with respect to the bitmap:

Next, we define a target bitmap and take its graphical device context:

Bitmap target = 
   new Bitmap(118, 97, PixelFormat.Format24bppRgb);
// perform some initalization on the bitmap ...
Graphics gtargetBmp = Graphics.FromImage(target);

We have following empty bitmap (the rectangle is to show its defining rectangle):

And relative to this bitmap (or device context) we define the target rectangle:

Rectangle destinationRect = new Rectangle(-31, -21, 121, 69);

This results in:

And finally we execute our DrawImage method saying:

  1. take this target bitmap (actally its device context) and in it we draw
  2. the Source Bitmap
  3. in the Destination Rectangle (relative to the target bitmap)
  4. using the Source Rectangle (relative to the source bitmap)

A visual presentation gives us:

And the final result is:

Voila, hope this helps someone in making sense of this method. As I said, it’s really not that difficult, just got to keep your head with it.


Sample code

Offline Maps: Added Import Layer and corrected version for Windows Mobile 6.0 – version 1.3.0

I’ve just released version 1.3.0 of the application.

The application allows you to download tiles served by google maps and openstreetmap to your harddrive and then view them offline, thus without an internet connection.

What’s changed

I have added a layer which allows you to import other maps like bitmaps and calibrate them with Google Maps or Open Street Maps.

I also fixed some bugs in the mobile version. It now works faster (allthough on my HTC Touch not fast enough yet) and GPS functioanlity is working.

You can get it at the Offline Maps page

Any remarks are always welcome.

Oh yeah, if you go look at the Offline Maps page: guess where we are going on holiday this year 🙂


These are some links I used for implementing the Import layer. Allthough it turned out I didn’t need the transformations for scaling.

bitmap transparency
Per Pixel Alpha Blend in C#
Drawing Transparent Images and Shapes using Alpha Blending
Using the AlphaBlend function

bitmap transformations
Image Transformation in C# with GDI+