Rotate a bitmap image

I am trying to rotate a second image and then paste that into the other but is not working. I don’t see the second image.

I have 1 image that is 200 x 200 (the compass rose) and a second image that is 15 x 149 (the compassPointer)

I tried the following.


Bitmap compass = compassBitmap;

compass.RotateImage(WeatherData.windDirection, 92, 25, compassPointerBitmap, 0, 0, 15, 149, 255);

compassImage.Bitmap = compass;
compassImage.Invalidate();

If I create the pointer image as a 149 x 149 and use this it works. I can’t get the thinner image to work. It needs to be to prevent over writing the underlying image.


compass.RotateImage(WeatherData.windDirection, 92, 25, compassPointerBitmap, 0, 0, 15, 149, 255);

Have I used the command correct? i.e. is the coordinates correct?

I’ve gotten it to partly work by making the image 149 x 149 and then rotating this only a new image and then drawing the resource image to the Image first and then the rotated one BUT I am getting duplicate pointer images. The previous one is still visible.


Bitmap compassCopy;
compassCopy = new Bitmap(compassPointerBitmap.Width, compassBitmap.Height);

compassCopy.RotateImage(WeatherData.windDirection, 0, 0, compassPointerBitmap, 0, 0, 149, 149, 255);

compassImage.Bitmap.MakeTransparent(Color.Black);
compassImage.Bitmap.DrawImage(0, 0, compassBitmap, 0, 0, compassBitmap.Width, compassBitmap.Height);
compassImage.Bitmap.DrawImage(25, 25, compassCopy, 0, 0, compassCopy.Width, compassCopy.Height);
compassImage.Invalidate();

If I invalidate the compassImage after the main bitmap is drawn then it works but I get a flickering of the pointer which I don’t want.

This works but flickers


compassImage.Bitmap.MakeTransparent(Color.Black);
compassImage.Bitmap.DrawImage(0, 0, compassBitmap, 0, 0, compassBitmap.Width, compassBitmap.Height);
compassImage.Invalidate();
compassImage.Bitmap.DrawImage(25, 25, compassCopy, 0, 0, compassCopy.Width, compassCopy.Height);
compassImage.Invalidate();

Got it all by myself so will post in case someone else has the same issue !!! :slight_smile:

You have to call Render() on the base image before drawing the second bitmap.


compassImage.Bitmap.MakeTransparent(Color.Black);
compassImage.Bitmap.DrawImage(0, 0, compassBitmap, 0, 0, compassBitmap.Width, compassBitmap.Height);
compassImage.Render();
compassImage.Bitmap.DrawImage(25, 25, compassCopy, 0, 0, compassCopy.Width, compassCopy.Height);
compassImage.Invalidate();

3 Likes

@ Dave McLaughlin - Looks like you are working on a cool project there. ;D

It sure is. NETMF has allowed me to get the bare bones of a system done in a matter of days so I have something I can demo to the client next week.

I can’t post anything just yet until I meet with them and get the clearance but it will be a commercial system so it will be available early next year.

3 Likes