直播节目.Net-位图从图像的右侧显示条纹? [英] Directshow & .Net - Bitmap shows stripe from right on left side of image?

查看:94
本文介绍了直播节目.Net-位图从图像的右侧显示条纹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例图片:



我正在使用DirectShow .net将网络摄像头素材插入我的程序。
为此,我将源摄像机添加到图形中,并添加了VideoMixingRenderer9。



这部分都可以正常工作,但是我在其中



我正在使用Marshal.PtrToSTructure从中创建BitmapInfoHeader lpDib,然后计算宽度/高度/步幅/&像素格式。



值得注意的是,我从GetCurrentImage调用获取的数据实际上是颠倒的-请注意对Cap.RotateFlip的调用。

  IntPtr lpDib; 
windowlessCtrl.GetCurrentImage(out lpDib);

BitmapInfoHeader头;
head =(BitmapInfoHeader)Marshal.PtrToStructure(lpDib,typeof(BitmapInfoHeader));
int width = head.Width;
int height = head.Height;
int步幅=宽度*(head.BitCount / 8);
PixelFormat pixelFormat = PixelFormat.Format24bppRgb;

开关(head.BitCount)
{
case 24:pixelFormat = PixelFormat.Format24bppRgb;打破;
情况32:pixelFormat = PixelFormat.Format32bppRgb;打破;
案例48:pixelFormat = PixelFormat.Format48bppRgb;打破;
默认值:抛出新的Exception( Unknown BitCount);
}

Cap = new Bitmap(width,height,stride,pixelFormat,lpDib);
Cap.RotateFlip(RotateFlipType.RotateNoneFlipY);
//如果我们在此处检查Cap(例如Cap.Save),我会看到奇数条。

我在这里完全迷路了。好像是某种偏移问题,我尝试了一些大步调整,但无济于事(只是造成了奇怪的对角线外观)。 div>

视频渲染器正在扩展位图以适合其自身的内存对齐需求,但是它将调整媒体类型以使其匹配。媒体类型中的VIDEOINFOHEADER(或VIDEOINFOHEADER2结构)将具有rcTarget矩形,该矩形定义较大位图中的有效区域。您可以在输入引脚上查询当前的媒体类型并掌握此信息。



您会发现渲染器只需要某些格式的扩展步长,因此也许最简单的方法是强制使用其他捕获格式。一种替代方法是使用样本捕获器过滤器代替VMR。



G


Sample Image:

I'm using DirectShow.net to get webcam footage into my program. To accomplish this, I'm adding the source camera to the graph, and a VideoMixingRenderer9.

That part is all working swimmingly, but the part where I extract a frame using GetCurrentImage(out lpDib) is having what I can only describe as an odd issue.

What I am doing is using Marshal.PtrToSTructure to create a BitmapInfoHeader from lpDib, then calculating the width / height / stride / & pixel format.

The problem comes when I look at the image stored in bitmap - It has a 10 px wide line down the left side that came from what is actually the right!

It is worth noting that the data I am getting from the GetCurrentImage call is actually upside down - note the call to Cap.RotateFlip.

IntPtr lpDib;
windowlessCtrl.GetCurrentImage(out lpDib);

BitmapInfoHeader head;
head = (BitmapInfoHeader)Marshal.PtrToStructure(lpDib, typeof(BitmapInfoHeader));
int width = head.Width;
int height = head.Height;
int stride = width * (head.BitCount / 8);
PixelFormat pixelFormat = PixelFormat.Format24bppRgb;

switch (head.BitCount)
{
    case 24: pixelFormat = PixelFormat.Format24bppRgb; break;
    case 32: pixelFormat = PixelFormat.Format32bppRgb; break;
    case 48: pixelFormat = PixelFormat.Format48bppRgb; break;
    default: throw new Exception("Unknown BitCount");
}

Cap = new Bitmap(width, height, stride, pixelFormat, lpDib);
Cap.RotateFlip(RotateFlipType.RotateNoneFlipY);
//if we examine Cap here (Cap.Save, for example) I'm seeing the odd stripe.

I'm completely lost here. Seems like some sort of offset issue, and I've tried tweaking with stride some, but to no avail (just creates odd diagonal look).

解决方案

The video renderer is extending the bitmap to suit its own memory alignment needs, but it will have adjusted the media type to match. The VIDEOINFOHEADER (or VIDEOINFOHEADER2 structure) in the media type will have an rcTarget rectangle that defines the valid area within the larger bitmap. You can query the current media type on the input pin and get hold of this information.

You will find that the renderer only needs this extended stride for some formats, so perhaps your simplest approach is to force a different capture format. An alternative is to use the sample grabber filter instead of the VMR.

G

这篇关于直播节目.Net-位图从图像的右侧显示条纹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆