예제 #1
0
        public void Open()
        {
            if (opened) {
            throw new InvalidOperationException();
             }
             if (tracker == null) {
            throw new InvalidOperationException("Tracking is not specified.");
             }
             // Get pixel format of primary screen
             PixelFormat pixelFormat;
             int bpp = GetPrimaryScreenBitDepth();
             switch (bpp) {
            case bpp16:
               pixelFormat = PixelFormat.Format16bppRgb555;
               break;
            case bpp24:
            case bpp32:
               pixelFormat = PixelFormat.Format24bppRgb;
               break;
            default:
               throw new NotSupportedException("PixelFormat is not supported.");
             }

             // Populate display element list
             List<IDisplayElement> displayElementList = new List<IDisplayElement>();
             displayElementList.Add(this.screenshot);
             if (displayWatermark) {
            displayElementList.Add(this.waterMark);
             }
             if (this.recordCursor) {
            displayElementList.Add(this.mouseCursor);
             }

             // Calc bitmap properties
             Rectangle bounds = this.tracker.Bounds;
             Size size = bounds.Size;
             int bytesPerPixel = Bitmap.GetPixelFormatSize(pixelFormat) / 8;
             int stride = (size.Width * bytesPerPixel);
             int nUnalignedBytes = stride % nAlignBytes;
             if (nUnalignedBytes != 0) {
            stride = stride + nAlignBytes - nUnalignedBytes;
             }
             int nBitmapBytes = stride * size.Height;
             int nExtraBytes = 4;  // NOTE: added + 4 for acc. violation problem with encoding 24bit in XVID codec (?!)

             // Allocate memory for bitmap bits
             this.pBitmapBits = Marshal.AllocHGlobal(nBitmapBytes + nExtraBytes);
             try {
            // Create bitmap
            this.bitmap = new Bitmap(size.Width, size.Height, stride, pixelFormat, this.pBitmapBits);
            this.bitmapBytes = nBitmapBytes;

            // Open displat elements
            foreach (IDisplayElement displayElement in displayElementList) {
               displayElement.Open(this.bitmap);
            }

            // Set fields
            this.displayElements = displayElementList.ToArray();
            this.format = new DisplayFormat(size, pixelFormat);
            this.opened = true;
             }
             finally {
            if (!this.opened) {
               this.Close();
            }
             }
        }
예제 #2
0
 private void SetupVideo(DisplayFormat videoFormat, VideoCompressor compressor, int fps)
 {
     int colorDepth = Bitmap.GetPixelFormatSize(videoFormat.PixelFormat);
      int width = videoFormat.Width;
      int height = videoFormat.Height;
      // Calculate pitch
      int bytesPerPixel = colorDepth / 8;
      int pitch = width * bytesPerPixel;
      int pitch_factor = 4;
      if (pitch % pitch_factor != 0) {
     pitch = pitch + pitch_factor - pitch % pitch_factor;
      }
      // Create AVI Stream
      Avi32Interop.AVISTREAMINFO asf = new Avi32Interop.AVISTREAMINFO();
      asf.dwRate = fps;
      asf.dwSuggestedBufferSize = pitch * height * bytesPerPixel;
      asf.dwScale = 1;
      asf.fccType = Avi32Interop.streamtypeVIDEO;
      asf.szName = null;
      asf.rcFrame = new Avi32Interop.RECT(0, 0, width, height);
      int hr = Avi32Interop.AVIFileCreateStream(this.pAviFile, out this.pVideoStream, ref asf);
      if (hr != 0) {
     throw new AviException("AVIFileCreateStream", hr);
      }
      // Set stream format
      Avi32Interop.BITMAPINFOHEADER bih = new Avi32Interop.BITMAPINFOHEADER();
      bih.biBitCount = (ushort)colorDepth;
      bih.biCompression = 0; // BI_RGB
      bih.biHeight = videoFormat.Height;
      bih.biPlanes = 1;
      bih.biSize = (uint)Marshal.SizeOf(bih);
      bih.biSizeImage = (uint)(pitch * height * (colorDepth / 8));
      bih.biWidth = videoFormat.Width;
      if (compressor != null && !compressor.Equals(VideoCompressor.None)) {
     // Setup compressor
     this.SetupVideoCompressor(compressor);
     hr = Avi32Interop.AVIStreamSetFormat(this.pAviCompressedStream, 0, ref bih, Marshal.SizeOf(bih));
      }
      else {
     hr = Avi32Interop.AVIStreamSetFormat(this.pVideoStream, 0, ref bih, Marshal.SizeOf(bih));
      }
      if (hr != 0) {
     throw new AviException("AVIStreamSetFormat", hr);
      }
 }
예제 #3
0
        public void Open()
        {
            if (opened)
            {
                throw new InvalidOperationException();
            }
            if (tracker == null)
            {
                throw new InvalidOperationException("Tracking is not specified.");
            }
            // Get pixel format of primary screen
            PixelFormat pixelFormat;
            int         bpp = GetPrimaryScreenBitDepth();

            switch (bpp)
            {
            case bpp16:
                pixelFormat = PixelFormat.Format16bppRgb555;
                break;

            case bpp24:
            case bpp32:
                pixelFormat = PixelFormat.Format24bppRgb;
                break;

            default:
                throw new NotSupportedException("PixelFormat is not supported.");
            }

            // Populate display element list
            List <IDisplayElement> displayElementList = new List <IDisplayElement>();

            displayElementList.Add(this.screenshot);
            if (displayWatermark)
            {
                displayElementList.Add(this.waterMark);
            }
            if (this.recordCursor)
            {
                displayElementList.Add(this.mouseCursor);
            }

            // Calc bitmap properties
            Rectangle bounds          = this.tracker.Bounds;
            Size      size            = bounds.Size;
            int       bytesPerPixel   = Bitmap.GetPixelFormatSize(pixelFormat) / 8;
            int       stride          = (size.Width * bytesPerPixel);
            int       nUnalignedBytes = stride % nAlignBytes;

            if (nUnalignedBytes != 0)
            {
                stride = stride + nAlignBytes - nUnalignedBytes;
            }
            int nBitmapBytes = stride * size.Height;
            int nExtraBytes  = 4; // NOTE: added + 4 for acc. violation problem with encoding 24bit in XVID codec (?!)

            // Allocate memory for bitmap bits
            this.pBitmapBits = Marshal.AllocHGlobal(nBitmapBytes + nExtraBytes);
            try {
                // Create bitmap
                this.bitmap      = new Bitmap(size.Width, size.Height, stride, pixelFormat, this.pBitmapBits);
                this.bitmapBytes = nBitmapBytes;

                // Open displat elements
                foreach (IDisplayElement displayElement in displayElementList)
                {
                    displayElement.Open(this.bitmap);
                }

                // Set fields
                this.displayElements = displayElementList.ToArray();
                this.format          = new DisplayFormat(size, pixelFormat);
                this.opened          = true;
            }
            finally {
                if (!this.opened)
                {
                    this.Close();
                }
            }
        }
예제 #4
0
 public void Open(string fileName, DisplayFormat videoFormat, int fps, VideoCompressor compressor, 
                SoundFormat audioFormat, AcmEncoder audioEncoder)
 {
     if (this.opened) {
     throw new InvalidOperationException();
      }
      if (string.IsNullOrEmpty(fileName)) {
     throw new ArgumentNullException("fileName");
      }
      this.video = videoFormat != null;
      this.audio = audioFormat != null;
      if (!this.audio && !this.video) {
     // There is nothing to do!
     throw new InvalidOperationException();
      }
      // Open AVI File
      int hr = Avi32Interop.AVIFileOpen(out this.pAviFile, fileName, Avi32Interop.OF_CREATE, IntPtr.Zero);
      if (hr != 0) {
     throw new AviException("AVIFileOpen", hr);
      }
      try {
     if (this.video) {
       this.SetupVideo(videoFormat, compressor, fps);
     }
     if (this.audio) {
        this.SetupAudio(audioFormat, audioEncoder);
     }
     this.opened = true;
      }
      finally {
     if (!this.opened) {
        this.Close();
     }
      }
 }