/// <summary> /// 从视频数据放回一个Bmp /// </summary> /// <param name="data"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> //public static Bitmap GetBitmapFromCallBackData(byte[] data, int width, int height) //{ // Bitmap bit = new Bitmap(width, height, PixelFormat.Format24bppRgb); // BitmapData bitdata = bit.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); // unsafe // { // byte* p = (byte*)(void*)bitdata.Scan0; // for (int i = 0; i < bit.Height; i++) // { // for (int k = 0; k < bitdata.Stride; k++) // { // int index = (bit.Height - (i + 1)) * bitdata.Stride + k; // p[0] = data[index]; // p++; // } // } // } // bit.UnlockBits(bitdata); // return bit; //} // start the web camera public void StartWebCam() { byte[] lpszName = new byte[100]; byte[] lpszVer = new byte[100]; ShowVideo.capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100); this.lwndC = ShowVideo.capCreateCaptureWindowA(lpszName, ShowVideo.WS_CHILD | ShowVideo.WS_VISIBLE, 0, 0, mWidth, mHeight, this.mControlPtr, 0); if (this.capDriverConnect(this.lwndC, 0)) { //有这句,图像才会和mWidth, mHeight相适应 ShowVideo.SendMessage(this.lwndC, ShowVideo.WM_CAP_SET_SCALE, 1, 0); this.capPreviewRate(this.lwndC, 66); this.capPreview(this.lwndC, true); //ShowVideo.BITMAPINFO bitmapinfo = new ShowVideo.BITMAPINFO(); //bitmapinfo.bmiHeader.biSize = ShowVideo.SizeOf(bitmapinfo.bmiHeader); //bitmapinfo.bmiHeader.biWidth = 353; //bitmapinfo.bmiHeader.biHeight = 288; //bitmapinfo.bmiHeader.biPlanes = 1; //bitmapinfo.bmiHeader.biBitCount = 24; //设置格式不一定成功,看设备是否支持 //this.capSetVideoFormat(this.lwndC, ref bitmapinfo, ShowVideo.SizeOf(bitmapinfo)); this.mFrameEventHandler = new ShowVideo.FrameEventHandler(FrameCallBack); this.capSetCallbackOnFrame(this.lwndC, this.mFrameEventHandler); ShowVideo.SetWindowPos(this.lwndC, 0, 0, 0, mWidth, mHeight, 6); //ShowVideo.SendMessage(this.lwndC, ShowVideo.WM_CAP_GET_VIDEOFORMAT, ShowVideo.SizeOf(bitmapinfo), ref bitmapinfo); } }
public void ReSetWindowSize(int width, int height) { ShowVideo.SetWindowPos(this.lwndC, 0, 0, 0, width, height, 6); }