首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

一个现有摄像头图像捕捉程序的有关问题(100分)

2012-03-31 
一个现有摄像头图像捕捉程序的问题(100分在线等)我是C#初学者,这里有一个程序运行出错请问是为什么?这个程

一个现有摄像头图像捕捉程序的问题(100分在线等)
我是C#初学者,这里有一个程序运行出错请问是为什么?
这个程序的目的就是显示摄像头的图像,采集图片之类的
出错信息:
未处理的“System.Resources.MissingManifestResourceException”类型的异常出现在 mscorlib.dll 中。

其他信息: 未能找到任何适合于指定的区域性或非特定区域性的资源。请确保在编译时已将“CapTureMovie.Form1.resources”正确嵌入或链接到程序集“cstest”,或者确保所有需要的附属程序集都可加载并已进行了完全签名。

程序如下:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;

namespace CapTureMovie
{
  /// <summary>  
  /// Form1 的摘要说明。  
  /// </summary>  
  public partial class Form1 : System.Windows.Forms.Form
  {
  private System.Windows.Forms.Button BtnCapTure;
  private System.Windows.Forms.Panel panel_Vedio;
  private int hHwnd;
  private System.Windows.Forms.Button BtnStop;
  private System.Windows.Forms.Label LbSysMsg;
  private System.Windows.Forms.Button button1;

  public struct videohdr_tag
  {
  public byte[] lpData;
  public int dwBufferLength;
  public int dwBytesUsed;
  public int dwTimeCaptured;
  public int dwUser;
  public int dwFlags;
  public int[] dwReserved;

  }
  public delegate bool CallBack(int hwnd, int lParam);
  /// <summary>  
  /// 必需的设计器变量。  
  /// </summary>  
  private System.ComponentModel.Container components = null;
  [DllImport("avicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  public static extern int capCreateCaptureWindowA([MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszWindowName, int dwStyle, int x, int y, int nWidth, short nHeight, int hWndParent, int nID);
  [DllImport("avicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  public static extern bool capGetDriverDescriptionA(short wDriver, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszName, int cbName, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpszVer, int cbVer);
  [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  public static extern bool DestroyWindow(int hndw);
  [DllImport("user32", EntryPoint = "SendMessageA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  public static extern int SendMessage(int hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)] object lParam);
  [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  public static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
  [DllImport("vfw32.dll")]
  public static extern string capVideoStreamCallback(int hwnd, videohdr_tag videohdr_tag);
  [DllImport("vicap32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  public static extern bool capSetCallbackOnFrame(int hwnd, string s);

  public Form1()
  {
  //  
  // Windows 窗体设计器支持所必需的  
  //  
  InitializeComponent();

  //  
  // TODO: 在 InitializeComponent 调用后添加任何构造函数代码  


  //  
  }

  /// <summary>  
  /// 清理所有正在使用的资源。  
  /// </summary>  
  protected override void Dispose(bool disposing)
  {
  if (disposing)
  {
  if (components != null)
  {
  components.Dispose();
  }
  }
  base.Dispose(disposing);
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>  
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改  
  /// 此方法的内容。  
  /// </summary>  
  private void InitializeComponent()
  {
  System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
  this.panel_Vedio = new System.Windows.Forms.Panel();
  this.BtnCapTure = new System.Windows.Forms.Button();
  this.BtnStop = new System.Windows.Forms.Button();
  this.LbSysMsg = new System.Windows.Forms.Label();
  this.button1 = new System.Windows.Forms.Button();
  this.SuspendLayout();
  //  
  // panel_Vedio  
  //  
  this.panel_Vedio.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel_Vedio.BackgroundImage")));
  this.panel_Vedio.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  this.panel_Vedio.Location = new System.Drawing.Point(8, 16);
  this.panel_Vedio.Name = "panel_Vedio";
  this.panel_Vedio.Size = new System.Drawing.Size(288, 224);
  this.panel_Vedio.TabIndex = 0;
  //  
  // BtnCapTure  
  //  
  this.BtnCapTure.Location = new System.Drawing.Point(24, 256);
  this.BtnCapTure.Name = "BtnCapTure";
  this.BtnCapTure.TabIndex = 1;
  this.BtnCapTure.Text = "图象采集";
  this.BtnCapTure.Click += new System.EventHandler(this.BtnCapTure_Click);
  //  
  // BtnStop  
  //  
  this.BtnStop.Enabled = false;
  this.BtnStop.Location = new System.Drawing.Point(136, 256);
  this.BtnStop.Name = "BtnStop";
  this.BtnStop.TabIndex = 1;
  this.BtnStop.Text = "停止采集";
  this.BtnStop.Click += new System.EventHandler(this.BtnStop_Click);
  //  
  // LbSysMsg  
  //  
  this.LbSysMsg.Location = new System.Drawing.Point(16, 296);
  this.LbSysMsg.Name = "LbSysMsg";
  this.LbSysMsg.Size = new System.Drawing.Size(240, 23);
  this.LbSysMsg.TabIndex = 2;
  //  
  // button1  
  //  
  this.button1.Location = new System.Drawing.Point(304, 48);
  this.button1.Name = "button1";
  this.button1.TabIndex = 3;
  this.button1.Text = "button1";
  this.button1.Click += new System.EventHandler(this.button1_Click);
  //  
  // Form1  


  //  
  this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  this.ClientSize = new System.Drawing.Size(400, 357);
  this.Controls.Add(this.button1);
  this.Controls.Add(this.LbSysMsg);
  this.Controls.Add(this.BtnCapTure);
  this.Controls.Add(this.panel_Vedio);
  this.Controls.Add(this.BtnStop);
  this.Name = "Form1";
  this.Text = "Form1";
  this.ResumeLayout(false);

  }
  #endregion


[解决办法]
你的Form1.resx或者Form1.zh-cn.resx没有编译进去。
[解决办法]
选择那个资源文件.resx,属性->生成操作->选择“嵌入的资源”
[解决办法]
为什么panel_Vedio会初始化设置一个背景图片?
lz应该这里看到抛出异常的吧,显然是你没有吧Form1.resx包含到工程里编译。
简单的解决可以这样,把这句设置panel_Vedio BackgroundImage语句删除:

C# code
///<summary>       ///       设计器支持所需的方法       -       不要使用代码编辑器修改       ///       此方法的内容。       ///       </summary>       private   void   InitializeComponent() {     //注掉这一句,因为没人用     //System.Resources.ResourceManager   resources   =   new   System.Resources.ResourceManager(typeof(Form1));      this.panel_Vedio   =   new   System.Windows.Forms.Panel();      this.BtnCapTure   =   new   System.Windows.Forms.Button();      this.BtnStop   =   new   System.Windows.Forms.Button();      this.LbSysMsg   =   new   System.Windows.Forms.Label();      this.button1   =   new   System.Windows.Forms.Button();      this.SuspendLayout();      //                //       panel_Vedio            //         //注掉这句,它从资源里取图片,没用。        //this.panel_Vedio.BackgroundImage   =   ((System.Drawing.Image)(resources.GetObject("panel_Vedio.BackgroundImage")));      this.panel_Vedio.BorderStyle   =   System.Windows.Forms.BorderStyle.Fixed3D;      this.panel_Vedio.Location   =   new   System.Drawing.Point(8,   16);      this.panel_Vedio.Name   =   "panel_Vedio";      this.panel_Vedio.Size   =   new   System.Drawing.Size(288,   224);      this.panel_Vedio.TabIndex   =   0; 

热点排行