예제 #1
0
        public static BitmapSource GetBitmapSource(this BitmapSourceInfo info)
        {
            var bs = BitmapSource.Create(
                info.PixelWidth,
                info.PixelHeight,
                info.DpiX,
                info.DpiY,
                info.PixelFormat,
                info.BitmapPalette,
                info.Buffer,
                info.Stride);

            return(bs);
        }
        public static BitmapSourceInfo ToGray8BppBitmapSourceInfo(this BitmapSource bitmapSource)
        {
            var info = new BitmapSourceInfo()
            {
                DpiX          = bitmapSource.DpiX,
                DpiY          = bitmapSource.DpiY,
                Stride        = bitmapSource.PixelWidth,
                PixelWidth    = bitmapSource.PixelWidth,
                PixelHeight   = bitmapSource.PixelHeight,
                PixelFormat   = bitmapSource.Format,
                BitmapPalette = bitmapSource.Palette,
            };

            var buffer = new byte[info.PixelWidth * info.PixelHeight];

            bitmapSource.CopyPixels(buffer, info.Stride, 0);
            info.Buffer = buffer;
            return(info);
        }