【发布时间】:2019-11-15 11:11:34
【问题描述】:
我是 C# 新手,现在使用佳能的 EDSDK 在图片框中实时查看相机。如何将实时取景图像旋转 180°?
我尝试在 liveView 建立后旋转图像
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);
实时视图正在运行,但未应用旋转。
注意:pictureBox 有属性WaitOnLoad=false
我假设我需要旋转某种图像流,尽管我不太了解 SDK 中的大部分代码。谁能帮助我,告诉我从哪里开始?
【问题讨论】:
-
这是一个 WinForms 应用程序吗?您是否能够显示有关如何创建 LiveViewPicBox(属性等)的更多详细信息。你想在什么事件中使用你的代码?这就是访问图像或图片框的事件中的所有代码吗?
-
我用更详细的代码更新了我的问题。这是一个 WinForms 应用程序。
-
LiveViewPicBox是一个简单的图片框,没有分配特殊属性。这是我正在使用的EDSDK示例。按钮点击触发MainForm.startLiveView() -
老实说,我什至看不到 SDK 代码中图片框上实际图像(流?)的设置位置。不管我挖多深。
-
您发布的旋转图像的代码是正确的。这可以通过创建一个新的 WinForms 应用程序来验证,该应用程序包含一个带有图像的 PictureBox,以及一个带有用于旋转它的代码的按钮。我的预感是由于未在 UI 线程上完成 LiveView,因此 PictureBox 未更新。
标签: c# winforms edsdk canon-sdk