将佳能实时取景图像旋转 180°



我是C#的新手,现在使用佳能的EDSDK在pictureBox中实时查看相机。如何将即时取景图像旋转180°?

我尝试在建立实时视图后旋转图像


主窗体.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;
}

相机.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);

实时取景工作正常,但未应用旋转。

注意:图片框具有属性WaitOnLoad=false

我假设有某种图像流我需要旋转,尽管我不了解 SDK 中的大部分代码。谁能帮助我,告诉我从哪里开始?

看起来您正在使用我在 CodeProject 中的教程。在这种情况下,您看错了东西。示例中有两个相关方法,传递当前实时取景帧的LiveViewUpdated事件处理程序(称为MainCamera_LiveViewUpdated)和实际绘制实时取景的图片框绘制事件(称为LiveViewPicBox_Paint)

MainCamera_LiveViewUpdated中,当前帧被读入Bitmap,图片框被"通知"它应该重绘自己。

LiveViewPicBox_Paint方法中,你将看到实际上并未使用图片框图像,而是使用PaintEventArgs传递给你的Graphics对象直接将图像绘制到控件上(这样做是出于性能原因)。

现在,您既拥有Graphics对象,又拥有实时取景框,您可以按照自己喜欢的任何方式绘制它。对于旋转,请在此处查看此答案:旋转图形?

最新更新