コード例 #1
0
        private static byte[] GetPixels(RenderTargetBitmap rtb, int width, int height)
        {
            int num = width * 4;
            FormatConvertedBitmap formatConvertedBitmap = new FormatConvertedBitmap();

            formatConvertedBitmap.BeginInit();
            formatConvertedBitmap.Source            = rtb;
            formatConvertedBitmap.DestinationFormat = PixelFormats.Bgra32;
            formatConvertedBitmap.EndInit();
            byte[] array = new byte[num * height];
            formatConvertedBitmap.CriticalCopyPixels(Int32Rect.Empty, array, num, 0);
            return(array);
        }
コード例 #2
0
ファイル: PenCursorManager.cs プロジェクト: beda2280/wpf-1
        /// <summary>
        /// Get bitmap pixel data in Bgra32 format from a custom Drawing.
        /// </summary>
        /// <param name="rtb">A bitmap</param>
        /// <param name="width">Bitmap width</param>
        /// <param name="height">Bitmap height</param>
        /// <returns></returns>
        private static byte[] GetPixels(RenderTargetBitmap rtb, int width, int height)
        {
            int strideColorBitmap = width * 4 /* 32 BitsPerPixel */;

            // Convert the bitmap from Pbgra32 to Bgra32
            FormatConvertedBitmap converter = new FormatConvertedBitmap();

            converter.BeginInit();
            converter.Source            = rtb;
            converter.DestinationFormat = PixelFormats.Bgra32;
            converter.EndInit();

            byte[] pixels = new byte[strideColorBitmap * height];

            // Call the internal method which skips the MediaPermission Demand
            converter.CriticalCopyPixels(Int32Rect.Empty, pixels, strideColorBitmap, 0);

            return(pixels);
        }
コード例 #3
0
        private byte[] GetDecodedPixels(Int32Rect bounds)
        {
            Debug.Assert(
                (bounds.X >= 0) &&
                (bounds.Y >= 0) &&
                ((bounds.X + bounds.Width) <= _pixelWidth) &&
                ((bounds.Y + bounds.Height) <= _pixelHeight)
                );

            int stride = bounds.Width * 4;

            byte[] pixels = new Byte[stride * bounds.Height];

            FormatConvertedBitmap converter = new FormatConvertedBitmap();

            converter.BeginInit();
            converter.Source            = _image;
            converter.DestinationFormat = PixelFormats.Pbgra32;
            converter.EndInit();

            converter.CriticalCopyPixels(bounds, pixels, stride, 0);

            return(pixels);
        }