Crash: How to rotate a bitmap?

I’m making a lot of progress learning my new cobra. It’s quite easy to make it do what I want.

But I can’t figure out how to rotate an image/bitmap. Is there a built-in function that I just don’t know about?

This is what I’m trying:


            _pressedButton.RotateImage(90, 1, 1, _pressedButton, 1, 1, 100, 100, 1);
            _imgButton.Bitmap = _pressedButton;

And I get:

Exception System.ArgumentException - 0xfd000000 (1)

#### Message: 
#### Microsoft.SPOT.Bitmap::RotateImage [IP: 0000] ####
#### GadgeteerApp3.Program::display_GestureDetected [IP: 0017] ####
#### Gadgeteer.Modules.GHIElectronics.Display_CP7::OnTouchEvent [IP: 00a1] ####
#### Gadgeteer.Modules.GHIElectronics.Display_CP7::_input_Interrupt [IP: 0006] ####
#### Gadgeteer.Interfaces.InterruptInput::OnInterruptEvent [IP: 0055] ####
#### System.Reflection.MethodBase::Invoke [IP: 0000] ####
#### Gadgeteer.Program::DoOperation [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 0020] ####

Justin

I remember that image should be square for rotation to work.

Adjusted the images to be square.

Adjusted the code as follows:


_pressedButton.RotateImage(90, 0, 0, _pressedButton, 0, 0, _pressedButton.Width, _pressedButton.Height, 255);
 _imgButton.Bitmap = _pressedButton;

Still fails

Is there a way to get more information out of the stack traces?

 _pressedButton = new Bitmap(Resources.GetBytes(Resources.BinaryResources.down), Bitmap.BitmapImageType.Jpeg);

@ JustinKScott -

You can’t rotate an image into itself.

For example the following code will “draw” your _pressedButton rotated into _display Bitmap.

Bitmap _display = new Bitmap(_pressedButton.Width, _pressedButton.Height);
_display.RotateImage(270, 0, 0, _pressedButton, 0, 0, 
_pressedButton.Width, _pressedButton.Height, 255);


I have just tried it. It works.

@ architect,

You nailed it!