I am new to C#, now using Canon's EDSDK having a live-view of the camera in a pictureBox. How is it possible to rotate the live-view image by 180°?
I tried rotating the image after the liveView is established
MainForm.cs
Camera MainCamera; // is instanciated elsewhere
public void startLiveView() {
MainCamera.StartLiveView();
// at this point, live-view is working and LiveViewPicBox contains the live-view
// this code has no effect:
Image img = LiveViewPicBox.Image;
img.RotateFlip(RotateFlipType.Rotate180FlipY);
LiveViewPicBox.Image = img;
}
Camera.cs
public void StartLiveView()
{
CheckState();
if (!IsLiveViewOn) SetSetting(PropertyID.Evf_OutputDevice, (int)EvfOutputDevice.PC);
}
public void SetSetting(PropertyID propID, object value, int inParam = 0)
{
CheckState();
MainThread.Invoke(() =>
{
int propsize;
DataType proptype;
ErrorHandler.CheckError(this, CanonSDK.EdsGetPropertySize(CamRef, propID, inParam, out proptype, out propsize));
ErrorHandler.CheckError(this, CanonSDK.EdsSetPropertyData(CamRef, propID, inParam, propsize, value));
});
}
SDKMethods.cs (CanonSDK)
[DllImport(DllPath)]
public extern static ErrorCode EdsGetPropertySize(IntPtr inRef, PropertyID inPropertyID, int inParam, out DataType outDataType, out int outSize);
[DllImport(DllPath)]
public extern static ErrorCode EdsSetPropertyData(IntPtr inRef, PropertyID inPropertyID, int inParam, int inPropertySize, [MarshalAs(UnmanagedType.AsAny), In] object inPropertyData);
The Live-View is working but no rotation is applied.
Note: The pictureBox has property WaitOnLoad=false
I assume there's some kind of image-stream which I'd need to rotate instead, though I do not understand much of the code in the SDK. Can anyone assist me, telling me where to start?
It looks like you are using my tutorial from CodeProject. In that case you are looking at the wrong thing. There are two relevant methods in the example, the LiveViewUpdated
event handler where the current live view frame is passed (called MainCamera_LiveViewUpdated
) and the picture box paint event where live view is actually drawn (called LiveViewPicBox_Paint
)
In MainCamera_LiveViewUpdated
the current frame is read into a Bitmap
and the picture box is "notified" that it should redraw itself.
In the LiveViewPicBox_Paint
method you'll see that the picture box image isn't actually used but the image is drawn onto the control directly using a Graphics
object passed to you by the PaintEventArgs
(this is done for performance reasons).
Now, that you have both the Graphics
object as well as the live view frame, you can draw it any way you like. For rotation, have a look at this answer here: Rotating graphics?