.net下使用VFW+DrawDibDraw的一个问题。。求大神
我想用C#做一个类型远程视频的程序,现在做到通过VFW获取到视频帧的步骤,按网上的说法,接这个帧数据是可以用DrawDib绘制出来,但我碰到的问题是
程序现在没有报错,但是数据没有显示出来,求大神路过看一眼,感激不尽,在线等,事后分数自当奉上
也可以联系QQ:84921392。谢谢。
********************调用代码*******************************
private int x = 0;
private void FrameCallBack(IntPtr lwnd, IntPtr lpVHdr)
{
x++;
VIDOHDR videoHeader = new VIDOHDR();
BITMAPINFOHEADER btcomeepre=new BITMAPINFOHEADER();
byte[] VideoData;
videoHeader = (VIDOHDR)GetStructure(lpVHdr, videoHeader);
VideoData = new byte[videoHeader.dwBytesUsed];
Copy(videoHeader.lpData, VideoData);
if (x == 1) //测试用,只绘制第一次捕捉到的页面。
{
DrawDibClass drawobj = new DrawDibClass(dispalyhandle); //传入显示控件,这里我用的一个PICTUREBOX
drawobj.Open();
drawobj.Draw(VideoData,dispalyhandle.Width,dispalyhandle.Height); //传入捕捉到的BMP数组,宽,高
drawobj.Close();
}
return; //测试用,下面暂时不需要。
// //display(dispalyhandle, 300, 300, VideoData, btcomeepre);
if (RecievedFrame != null)
{
RecievedFrame(VideoData);
}
}
***********************附上DrawDibClass的代码**************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
namespace Monitoring
{
public class DrawDibClass
{
public Rectangle SrcRect, DstRect;
IntPtr hdd;
public Control Control;
public Monitoring.Camera.BITMAPINFOHEADER BITMAPINFOHEADER;
public IntPtr Handle
{
get { return this.hdd; }
}
public DrawDibClass(Control display)
{
Control = display;
this.SrcRect = this.DstRect = new Rectangle(0, 0, 160, 120);
}
public void Open()
{
this.hdd = DrawDibOpen();
BITMAPINFOHEADER.biCompression = 0;
BITMAPINFOHEADER.biWidth = 320;
BITMAPINFOHEADER.biHeight = 240;
BITMAPINFOHEADER.biPlanes = 1;
BITMAPINFOHEADER.biBitCount = 24;
BITMAPINFOHEADER.biXpelsPerMeter = 0;
BITMAPINFOHEADER.biYpelsPerMeter = 0;
BITMAPINFOHEADER.biClrImportant = 0;
BITMAPINFOHEADER.biSizeImage = 230400;
BITMAPINFOHEADER.biSize = Marshal.SizeOf(BITMAPINFOHEADER);
//Debug.Assert(hdd != IntPtr.Zero);
//bool b = DrawDibBegin(hdd, IntPtr.Zero, this.DstRect.Width, this.DstRect.Height, ref this.BITMAPINFOHEADER, this.SrcRect.Width, this.SrcRect.Height, 0);
}
public void Draw(byte[] data, int width, int height)
{
using (Graphics g = this.Control.CreateGraphics())
{
IntPtr hdc = g.GetHdc();
bool b = DrawDibDraw(
hdd,
hdc,
this.DstRect.X,
this.DstRect.Y,
width,
height,
ref this.BITMAPINFOHEADER,
data,
this.SrcRect.X,
this.SrcRect.Y, width, height, 0);
g.ReleaseHdc(hdc);
}
}
public void Draw(byte[] data)
{
using (Graphics g = this.Control.CreateGraphics())
{
IntPtr hdc = g.GetHdc();
bool b = DrawDibDraw(
hdd,
hdc,
this.DstRect.X,
this.DstRect.Y,
this.DstRect.Width,
this.DstRect.Height,
ref this.BITMAPINFOHEADER,
data,
this.SrcRect.X,
this.SrcRect.Y, this.SrcRect.Width, this.SrcRect.Height, 0);
g.ReleaseHdc(hdc);
}
}
public void Close()
{
if (hdd != IntPtr.Zero)
{
DrawDibEnd(hdd);
DrawDibClose(hdd);
}
}
public bool IsOpened
{
get { return this.hdd != IntPtr.Zero; }
}
#region
/*
** DrawDibOpen()
**
*/
[DllImport("MSVFW32.dll")]
public static extern IntPtr DrawDibOpen();
/*
** DrawDibClose()
**
*/
[DllImport("MSVFW32.dll")]
public static extern bool DrawDibClose(IntPtr hdd);
[DllImport("MSVFW32.dll")]
public static extern bool DrawDibBegin(
IntPtr hdd,
IntPtr hdc,
int dxDst,
int dyDst,
ref Monitoring.Camera.BITMAPINFOHEADER lpbi,
int dxSrc,
int dySrc,
int wFlags
);
[DllImport("MSVFW32.dll")]
public static extern bool DrawDibEnd(IntPtr hdd);
/*
** DrawDibDraw()
**
** actualy draw a DIB to the screen.
**
*/
[DllImport("MSVFW32.dll")]
public static extern bool DrawDibDraw(
IntPtr hdd,
IntPtr hdc,
int xDst,
int yDst,
int dxDst,
int dyDst,
ref Monitoring.Camera.BITMAPINFOHEADER lpbi,
byte[] lpBits,
int xSrc,
int ySrc,
int dxSrc,
int dySrc,
uint wFlags
);
#endregion
}
}
.net vfw drawdib 视频 --------------------编程问答-------------------- 路过,我也想知道答案,帮项 --------------------编程问答-------------------- 现在图像是有了,但是还原的图象不对,是黑白的,还是倒着的,总之不对,如图。 --------------------编程问答-------------------- 自己再顶顶,希望大神来稍作指点
补充:.NET技术 , C#