DrawImage高度参数不起作用

时间:2015-03-30 15:55:00

标签: c++ winforms visual-studio-2012 drawimage

我正在使用VS2012 c ++ / cli创建一个WinForms应用程序,并使用DrawImage显示从网络摄像头捕获的高清图像。

图像是1920 x 1080位图,我试图在Panel控件上显示。小组是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.但是,图像将不会显示。

如果我更改高度参数以指定面板 - &gt;底部(这是应用程序中的绝对位置 - ~630),图像会显示并且尺寸正确,但宽度不正确。< / p>

知道我做错了什么或如何正确调整大小和显示图像?

这是代码的完整版本。

    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);
    }

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我想出来了。存储位图的数组已初始化,但初始化范围不够持久。因此,存储在阵列中的引用可能被垃圾清理。由于一些奇怪的原因,揭示的唯一方法是drawimage调用的垂直参数。一旦我更正了初始化,drawimage调用就能正常工作。