Exemplo n.º 1
0
        /// <summary>
        /// Performs both conversion and resize in a single operation
        /// </summary>
        /// <param name="newPixelType"></param>
        /// <param name="newSize"></param>
        /// <returns></returns>
        public PlanarImage ConvertAndResize(PixelAlignmentType newPixelType, Size newSize)
        {
            PlanarImage result = new PlanarImage(newSize.Width, newSize.Height, newPixelType);

            ConverterResizer.Apply(this, result);
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resizes planar image
        /// </summary>
        /// <param name="newSize"></param>
        /// <returns></returns>
        public PlanarImage Resize(Size newSize)
        {
            PlanarImage result = new PlanarImage(newSize.Width, newSize.Height, this.PixelType);

            ConverterResizer.Apply(this, result);
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Converts planar image to another pixel alignment type
        /// </summary>
        /// <param name="newPixelType"></param>
        /// <returns></returns>
        public PlanarImage Convert(PixelAlignmentType newPixelType)
        {
            PlanarImage result = new PlanarImage(this.Width, this.Height, newPixelType);

            ConverterResizer.Apply(this, result);
            return(result);
        }
        public bool SetupSurface(int videoWidth, int videoHeight, FrameFormat format)
        {
            this.pixelType = ConvertToPixelFormat(format);
            if (pixelType == PixelAlignmentType.NotSupported)
            {
                return false;
            }

            this.width = videoWidth;
            this.height = videoHeight;
            switch (format)
            {
                case FrameFormat.YV12:
                case FrameFormat.NV12:
                    this.frameSize = this.width * this.height * 3 / 2;
                    break;

                case FrameFormat.YUY2:
                case FrameFormat.UYVY:
                case FrameFormat.RGB15: // rgb555
                case FrameFormat.RGB16: // rgb565
                    this.frameSize = this.width * this.height * 2; // 每个像素2字节
                    break;

                case FrameFormat.RGB32:
                case FrameFormat.ARGB32:
                    this.frameSize = this.width * this.height * 4; // 每个像素4字节
                    break;

                default:
                    return false;
            }

            this.imageSource = new WriteableBitmap(videoWidth, videoHeight, DPI_X, DPI_Y, System.Windows.Media.PixelFormats.Bgr32, null);
            this.imageSourceRect = new Int32Rect(0, 0, videoWidth, videoHeight);

            System.Drawing.Size size = new System.Drawing.Size(videoWidth, videoHeight);
            this.converter = new ConverterResizer(size, pixelType, size, PixelAlignmentType.BGRA);

            this.NotifyImageSourceChanged();

            return true;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Converts System.Drawing.Bitmap object into planar image
 /// </summary>
 /// <param name="bitmap"></param>
 /// <param name="pixelType"></param>
 /// <returns></returns>
 public static PlanarImage Load(Bitmap bitmap, PixelAlignmentType pixelType)
 {
     VerifyIsSupported(bitmap.PixelFormat);
     return(ConverterResizer.FromBitmap(bitmap, pixelType));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Convert planar image to .NET Bitmap object
 /// </summary>
 /// <param name="format"></param>
 /// <returns></returns>
 public Bitmap ToBitmap(PixelFormat format)
 {
     VerifyIsSupported(format);
     return(ConverterResizer.ToBitmap(this, format));
 }