- 爱易网页
 
                        - 
                            C#教程
 
                        - 将Image图片保存为AVI文件,该怎么解决 
 
                         
                    
                    
                    日期:2014-05-18  浏览次数:21218 次 
                    
                        
                         将Image图片保存为AVI文件
我用c#编写一个从网络摄像机上获取图像并保存为视频的程序时,通过摄像机的SDK里的ActiveX控件能获得的一个image对象,该iamge里有用Bitmap格式抓取的当前监控到的一帧视频图像,该图像可以用iamge的Save方法保存为一个bmp图片文件,现在我想把这个图像直接保存到一个AVI文件中(也就是把这一个一个返回的iamge图像直接做成一个AVI视频文件),向各位高手请教应该怎么做?
图片获取和保存为bmp文件的代码如下,保存是成功的。
  private int m_savecount= 0;
  private void save()
         {
             m_savecount = m_savecount + 1;
             Image m_objImage = this.axipropsapiCtrl1.GetBitmapImage();//axipropsapiCtrl1为SDK里的ActiveX控件
              
             m_objImage.Save("d:/" + m_savecount.ToString() + " .bmp");
              
         }
------解决方案--------------------
public void Close()
       {
           AVIStreamRelease(_ps);
           AVIStreamRelease(_psCompressed);
           AVIFileRelease(_pfile);
           AVIFileExit();
       }
       //// <summary>
       /// 创建流文件 
       /// </summary> 
       private bool CreateStream()
       {
           bool bReval = false;
           AVISTREAMINFOW strhdr = new AVISTREAMINFOW();
           strhdr.fccType = _fccType;
           strhdr.fccHandler = _fccHandler;
           strhdr.dwFlags = 0;
           strhdr.dwCaps = 0;
           strhdr.wPriority = 0;
           strhdr.wLanguage = 0;
           strhdr.dwScale = 1;
           strhdr.dwRate = _frameRate;
           strhdr.dwStart = 0;
           strhdr.dwLength = 0;
           strhdr.dwInitialFrames = 0;
           strhdr.dwSuggestedBufferSize = _height * _stride;
           strhdr.dwQuality = 0xffffffff;
           strhdr.dwSampleSize = 0;
           strhdr.rect_top = 0;
           strhdr.rect_left = 0;
           strhdr.rect_bottom = _height;
           strhdr.rect_right = _width;
           strhdr.dwEditCount = 0;
           strhdr.dwFormatChangeCount = 0;
           strhdr.szName0 = 0;
           strhdr.szName1 = 0;
           int hr = AVIFileCreateStream(_pfile, out _ps, ref strhdr);
           if (hr != 0)
           {
               bReval = true;
               throw new AviException("AVIFileCreateStream");
           }
           return bReval;
       }
       //// <summary>
       /// 设置参数
       /// </summary>  
       unsafe private void SetOptions()
       {
           AVICOMPRESSOPTIONS opts = new AVICOMPRESSOPTIONS();
           opts.fccType = _fccType;
           opts.fccHandler = 0;
           opts.dwKeyFrameEvery = 0;
           opts.dwQuality = 0;
           opts.dwFlags = 0;
           opts.dwBytesPerSecond = 0;
           opts.lpFormat = new IntPtr(0);
           opts.cbFormat = 0;
           opts.lpParms = new IntPtr(0);
           opts.cbParms = 0;
           opts.dwInterleaveEvery = 0;
           AVICOMPRESSOPTIONS* p = &opts;
           AVICOMPRESSOPTIONS** pp = &p;
           IntPtr x = _ps;
           IntPtr* ptr_ps = &x;
           AVISaveOptions(0, 0, 1, ptr_ps, pp);
           int hr = AVIMakeCompressedStream(out _psCompressed, _ps, ref opts, 0);
           if (hr != 0)
           {
               throw new AviException("AVIMakeCompressedStream");
           }
           BITMAPINFOHEADER bi = new BITMAPINFOHEADER();
           bi.biSize = 40;
           bi.biWidth = (Int32)_width;
           bi.biHeight = (Int32)_height;
           bi.biPlanes = 1;
           bi.biBitCount = 24;
           bi.biCompression = 0;
           bi.biSizeImage = _stride * _height;
           bi.biXPelsPerMeter = 0;
           bi.biYPelsPerMeter = 0;