日期:2014-05-18  浏览次数:21256 次

怎么实现摄像头全屏
如下代码怎么让摄像头全屏
form1.cs

  private void Form1_Load(object sender, EventArgs e)
  {
  w = Screen.AllScreens[0].Bounds.Width;
  h = Screen.AllScreens[0].Bounds.Height;
  b_play.Enabled = false;
  b_stop.Enabled = true;
  panelPreview.Size = new Size(1024, 768);
  wc = new WebCamera(panelPreview.Handle, panelPreview.Width, panelPreview.Height);
  wc.StartWebCam();
  }


showvideo.cs

  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_VISIBLE | showVideo.WS_CHILD, 0, 0, mWidth, mHeight, mControlPtr, 0);

  if (this.capDriverConnect(this.lwndC, 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 = 352;
  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);
  }

  }

------解决方案--------------------
我晕
wc = new WebCamera(panelPreview.Handle, panelPreview.Width, panelPreview.Height);
你这个传递的参数是:预览框句柄,预览框宽,预览框高
你只需要将预览框设置成和屏幕同样大小,就OK
------解决方案--------------------
this.lwndC = showVideo.capCreateCaptureWindowA(lpszName, showVideo.WS_VISIBLE | showVideo.WS_CHILD, 0, 0, mWidth, mHeight, mControlPtr, 0);

mWidth 宽
mHeight 高
------解决方案--------------------
得到视频大小后,resize到新的picturebox里
------解决方案--------------------
探讨
引用:
this.lwndC = showVideo.capCreateCaptureWindowA(lpszName, showVideo.WS_VISIBLE | showVideo.WS_CHILD, 0, 0, mWidth, mHeight, mControlPtr, 0);

mWidth 宽
mHeight 高



在构造函数里就已经定……

------解决方案--------------------
调小吧
------解决方案--------------------
C# code
/*
 * Title: Webcam Monitor
 * Author: Ahsun
 * Date: April 22, 2010
 * Email: ahsun.chen@gmail.com
 * MSN: ahsun.chen@hotmail.com
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.IO;


namespace WebcamMini
{
    public partial class Webcam : Form
    {
        public Webcam()
        {
            InitializeComponent();
        }
        const short WM_CAP = 1024;
        const int WM_CAP_DRIVER_CONNECT = WM_CAP + 10;
        const int WM_CAP_DRIVER_DISCONNECT = WM_CAP + 11;
        const int WM_CAP_EDIT_COPY = W