进入全屏并返回 C++/CLI 后重新绘制图像
我正在构建应用程序,它使用 StrechDIBits 在标签的 hdc 上绘制原始位图图像。
ptr = g->GetHdc();
dc = (HDC)ptr.ToInt32 ();
SetStretchBltMode (dc, COLORONCOLOR);
StretchDIBits (dc, 0, 0, (int) (LabelPictureShow->Width), (int) (LabelPictureShow->Height), 0, 0, width, height, data, bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
g->ReleaseHdc (ptr);
这样我就可以绘制整个视频流,从流中一张又一张图片,效果非常完美。我还有在整个屏幕上调整表单和标签大小以实现全屏的功能,这在播放视频时也很有效。
但是,当我停止视频或仅发送一张图片并调用全屏功能时。它不会重新绘制图像,这是我的问题。我尝试使用表单和标签的 Paint Event、Resize Event 来在调整大小后再次绘制图像,但没有任何效果。当我进入全屏或恢复到正常大小时,我的图像会短暂闪烁,但随后它会被控件的颜色重新绘制并消失。我尝试将绘画代码与 StretchDIBits 放在任何地方,但都不起作用。非常感谢任何帮助或建议。
编辑:对我来说悲伤的是,当我将绘画代码放入例如标签的单击事件中时,它工作正常......
I'm building application, which paints raw bitmap images on label's hdc using StrechDIBits.
ptr = g->GetHdc();
dc = (HDC)ptr.ToInt32 ();
SetStretchBltMode (dc, COLORONCOLOR);
StretchDIBits (dc, 0, 0, (int) (LabelPictureShow->Width), (int) (LabelPictureShow->Height), 0, 0, width, height, data, bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
g->ReleaseHdc (ptr);
This way I draw whole videostream, one picture from stream after another, which works perfect. I have also function which resize my form and label over whole screen for realizing a full screen, wchich also works great when playing video.
But, when I stop the video or send only one picture and call the full scren function. It will not repaint the image and that's my problem. I tried to use Paint Event, Resize Event both of form and label for painting the image again after resizing, but nothing works. When I get fullscreen or back to normal size, my image flashes for short moment but then it's repainted by control's color and dissappears. I've tried to put the painting code with StretchDIBits everywhere both nothing works. Any help or advice is really appreciated.
edit:the sad thing for me is, that when i put the painting code in, for example, click event of label, it works fine...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过使用其他项目中使用的自定义 PaintBox 控件来解决。该控件使用重写的 OnPaint 方法来重绘图像。不知何故,这个解决方案有效,但之前几乎相同的解决方案却无效。
Solved by using custom PaintBox control used in other project. This control uses overwritten OnPaint method where the image is redrawn. Somehow this solution works, but previous almost same solution not.