我是C#的新手,现在使用佳能的 EDSDK 在pictureBox中实时查看相机。如何将实时取景图像旋转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中的很多代码。谁能帮我,告诉我从哪里开始?
答案 0 :(得分:2)
您似乎正在使用我的CodeProject教程。在这种情况下,您正在看错东西。该示例中有两种相关方法:LiveViewUpdated
事件处理程序,其中传递了当前实时取景框(称为MainCamera_LiveViewUpdated
)和图片框绘制事件,其中实际绘制了实时取景(称为{{1 }})
在LiveViewPicBox_Paint
中,当前帧被读入MainCamera_LiveViewUpdated
,并且图片框“已通知”它应该重新绘制自己。
在Bitmap
方法中,您会看到图片框图像并未真正使用,但是图像是通过{{1 }}(这样做是出于性能方面的考虑。)
现在,您既有LiveViewPicBox_Paint
对象又有实时取景框架,则可以按自己喜欢的任何方式绘制它。要进行轮换,请在此处查看以下答案:Rotating graphics?