DrawImage 高度参数不起作用
DrawImage Height Parameter Not Working
我正在使用 VS2012 c++/cli 制作一个 WinForms 应用程序,并使用 DrawImage 显示从网络摄像头捕获的高清图像。
图像是 1920 x 1080 位图,我试图在面板控件上显示。面板为 240 x 135(即正好是高清图像的 1/8)。
我调用DrawImage如下:
System::Drawing::Rectangle destRect = System::Drawing::Rectangle(0,0,Cam0Panel->Width,Cam0Panel->Height);
g->DrawImage(b,destRect);
这应该指定在面板上的相对 0,0 位置绘制图像并将图像的大小设置为 240 x 135。但是,图像不会显示。
如果我更改 Height 参数以指定 Panel->Bottom(这是应用程序中的绝对位置 - ~630),图像会显示并且宽度大小正确,但高度大小不正确。
知道我做错了什么或如何正确调整和显示图像吗?
这是代码的完整版本。
void Cam0Panel_Paint( Object^ /*sender*/, System::Windows::Forms::PaintEventArgs^ e )
{
System::Drawing::Bitmap^ b = ImageWinArray[CHANNEL_SELECT0];
Graphics^ g = e->Graphics;
g->InterpolationMode = System::Drawing::Drawing2D::InterpolationMode::Bilinear;
g->CompositingMode = System::Drawing::Drawing2D::CompositingMode::SourceCopy;
System::Drawing::Rectangle destRect = System::Drawing::Rectangle(0,0,Cam0Panel->Width,Cam0Panel->Bottom);
g->DrawImage(b,destRect);
}
感谢您的帮助。
我想通了。存储位图的数组已初始化,但初始化范围不够持久。因此,存储在数组中的引用可能被垃圾清理。出于某种奇怪的原因,显示这一点的唯一方法是 drawimage 调用中的垂直参数。一旦我更正了初始化,drawimage 调用就可以正常工作了。
我正在使用 VS2012 c++/cli 制作一个 WinForms 应用程序,并使用 DrawImage 显示从网络摄像头捕获的高清图像。
图像是 1920 x 1080 位图,我试图在面板控件上显示。面板为 240 x 135(即正好是高清图像的 1/8)。
我调用DrawImage如下:
System::Drawing::Rectangle destRect = System::Drawing::Rectangle(0,0,Cam0Panel->Width,Cam0Panel->Height);
g->DrawImage(b,destRect);
这应该指定在面板上的相对 0,0 位置绘制图像并将图像的大小设置为 240 x 135。但是,图像不会显示。
如果我更改 Height 参数以指定 Panel->Bottom(这是应用程序中的绝对位置 - ~630),图像会显示并且宽度大小正确,但高度大小不正确。
知道我做错了什么或如何正确调整和显示图像吗?
这是代码的完整版本。
void Cam0Panel_Paint( Object^ /*sender*/, System::Windows::Forms::PaintEventArgs^ e )
{
System::Drawing::Bitmap^ b = ImageWinArray[CHANNEL_SELECT0];
Graphics^ g = e->Graphics;
g->InterpolationMode = System::Drawing::Drawing2D::InterpolationMode::Bilinear;
g->CompositingMode = System::Drawing::Drawing2D::CompositingMode::SourceCopy;
System::Drawing::Rectangle destRect = System::Drawing::Rectangle(0,0,Cam0Panel->Width,Cam0Panel->Bottom);
g->DrawImage(b,destRect);
}
感谢您的帮助。
我想通了。存储位图的数组已初始化,但初始化范围不够持久。因此,存储在数组中的引用可能被垃圾清理。出于某种奇怪的原因,显示这一点的唯一方法是 drawimage 调用中的垂直参数。一旦我更正了初始化,drawimage 调用就可以正常工作了。