Ejemplo n.º 1
0
        public void updateBitmap(Bitmap image, copyBitmapOptions options = copyBitmapOptions.None)
        {
            lock (image)
            {
                if (image.Width != this.FrameSize.Width || image.Height != this.FrameSize.Height)
                {
                    throw new ArgumentException("Bitmap size if not acceptable.");
                }
                if (image.PixelFormat == PixelFormat.Format24bppRgb)
                {
                    options |= copyBitmapOptions.Force24BitRGB;
                }
                else if ((options & copyBitmapOptions.Force24BitRGB) != copyBitmapOptions.Force24BitRGB)
                {
                    throw new ArgumentException("Requested RGB888 operation on a non-RGB24 bitmap.");
                }

                System.Drawing.Imaging.PixelFormat desiredFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
                switch (this.VideoMode.DataPixelFormat)
                {
                case VideoMode.PixelFormat.RGB888:
                    desiredFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
                    break;

                case VideoMode.PixelFormat.GRAY8:
                    desiredFormat = System.Drawing.Imaging.PixelFormat.Format8bppIndexed;
                    break;

                case VideoMode.PixelFormat.DEPTH_1MM:
                case VideoMode.PixelFormat.GRAY16:
                    desiredFormat = System.Drawing.Imaging.PixelFormat.Format16bppGrayScale;
                    break;

                default:
                    throw new BadImageFormatException("Pixel format is not acceptable for bitmap converting.");
                }
                if ((options & copyBitmapOptions.Force24BitRGB) != copyBitmapOptions.Force24BitRGB &&
                    desiredFormat != image.PixelFormat)
                {
                    throw new ArgumentException("Requested bitmap pixel format is not suitable for this data.");
                }
                BitmapData destBits = image.LockBits(new Rectangle(new Point(0, 0), image.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, image.PixelFormat);
                VideoFrameRef_copyDataTo(this.Handle, destBits.Scan0, destBits.Stride, options);
                image.UnlockBits(destBits);
            }
        }
Ejemplo n.º 2
0
        public Bitmap toBitmap(copyBitmapOptions options = copyBitmapOptions.None)
        {
            System.Drawing.Imaging.PixelFormat format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
            switch (this.VideoMode.DataPixelFormat)
            {
            case VideoMode.PixelFormat.RGB888:
                format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
                break;

            case VideoMode.PixelFormat.GRAY8:
                format = System.Drawing.Imaging.PixelFormat.Format8bppIndexed;
                break;

            case VideoMode.PixelFormat.DEPTH_1MM:
            case VideoMode.PixelFormat.GRAY16:
                format = System.Drawing.Imaging.PixelFormat.Format16bppGrayScale;
                break;

            default:
                throw new BadImageFormatException("Pixel format is not acceptable for bitmap converting.");
            }
            if ((options & copyBitmapOptions.Force24BitRGB) == copyBitmapOptions.Force24BitRGB)
            {
                format = PixelFormat.Format24bppRgb;
            }
            Bitmap destination = new Bitmap(this.FrameSize.Width, this.FrameSize.Height, format);

            if (format == PixelFormat.Format8bppIndexed)
            {
                for (int i = 0; i < 256; i++)
                {
                    destination.Palette.Entries[i] = Color.FromArgb(i, i, i);
                }
            }
            updateBitmap(destination, options);
            return(destination);
        }
Ejemplo n.º 3
0
 static extern void VideoFrameRef_copyDataTo(IntPtr objectHandler, IntPtr dstData, int dstStride, copyBitmapOptions options);
Ejemplo n.º 4
0
        public void updateBitmap(Bitmap image, copyBitmapOptions options = copyBitmapOptions.None)
        {
            lock (image)
            {
                if (image.Width != this.FrameSize.Width || image.Height != this.FrameSize.Height)
                    throw new ArgumentException("Bitmap size if not acceptable.");
                if (image.PixelFormat == PixelFormat.Format24bppRgb)
                    options |= copyBitmapOptions.Force24BitRGB;
                else if ((options & copyBitmapOptions.Force24BitRGB) != copyBitmapOptions.Force24BitRGB)
                    throw new ArgumentException("Requested RGB888 operation on a non-RGB24 bitmap.");

                System.Drawing.Imaging.PixelFormat desiredFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
                switch (this.VideoMode.DataPixelFormat)
                {
                    case VideoMode.PixelFormat.RGB888:
                        desiredFormat = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
                        break;
                    case VideoMode.PixelFormat.GRAY8:
                        desiredFormat = System.Drawing.Imaging.PixelFormat.Format8bppIndexed;
                        break;
                    case VideoMode.PixelFormat.DEPTH_1MM:
                    case VideoMode.PixelFormat.GRAY16:
                        desiredFormat = System.Drawing.Imaging.PixelFormat.Format16bppGrayScale;
                        break;
                    default:
                        throw new BadImageFormatException("Pixel format is not acceptable for bitmap converting.");
                }
                if ((options & copyBitmapOptions.Force24BitRGB) != copyBitmapOptions.Force24BitRGB &&
                    desiredFormat != image.PixelFormat)
                    throw new ArgumentException("Requested bitmap pixel format is not suitable for this data.");
                BitmapData destBits = image.LockBits(new Rectangle(new Point(0, 0), image.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, image.PixelFormat);
                VideoFrameRef_copyDataTo(this.Handle, destBits.Scan0, destBits.Stride, options);
                image.UnlockBits(destBits);
            }
        }
Ejemplo n.º 5
0
 public Bitmap toBitmap(copyBitmapOptions options = copyBitmapOptions.None)
 {
     System.Drawing.Imaging.PixelFormat format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
     switch (this.VideoMode.DataPixelFormat)
     {
         case VideoMode.PixelFormat.RGB888:
             format = System.Drawing.Imaging.PixelFormat.Format24bppRgb;
             break;
         case VideoMode.PixelFormat.GRAY8:
             format = System.Drawing.Imaging.PixelFormat.Format8bppIndexed;
             break;
         case VideoMode.PixelFormat.DEPTH_1MM:
         case VideoMode.PixelFormat.GRAY16:
             format = System.Drawing.Imaging.PixelFormat.Format16bppGrayScale;
             break;
         default:
             throw new BadImageFormatException("Pixel format is not acceptable for bitmap converting.");
     }
     if ((options & copyBitmapOptions.Force24BitRGB) == copyBitmapOptions.Force24BitRGB)
         format = PixelFormat.Format24bppRgb;
     Bitmap destination = new Bitmap(this.FrameSize.Width, this.FrameSize.Height, format);
     if (format == PixelFormat.Format8bppIndexed)
         for (int i = 0; i < 256; i++)
             destination.Palette.Entries[i] = Color.FromArgb(i, i, i);
     updateBitmap(destination, options);
     return destination;
 }
Ejemplo n.º 6
0
 static extern void VideoFrameRef_copyDataTo(IntPtr objectHandler, IntPtr dstData, int dstStride, copyBitmapOptions options);