码迷,mamicode.com
首页 > 其他好文 > 详细

BitmapSource

时间:2019-12-14 18:53:58      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:private   orm   div   vat   height   style   copy   for   str   

来自:https://stackoverflow.com/questions/8311805/bitmapsource-copypixels-byte-bitmapsource-how-to-do-this-simple

        private byte[] BitmapSourceToArray(BitmapSource bitmapSource)
        {
            // Stride = (width) x (bytes per pixel)
            int stride = (int)bitmapSource.PixelWidth * ((bitmapSource.Format.BitsPerPixel + 7) / 8);
            byte[] pixels = new byte[(int)bitmapSource.PixelHeight * stride];

            bitmapSource.CopyPixels(pixels, stride, 0);

            return pixels;
        }

        private BitmapSource BitmapSourceFromArray(byte[] pixels, int width, int height)
        {
            WriteableBitmap bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null);

            bitmap.WritePixels(new Int32Rect(0, 0, width, height), pixels, width * ((bitmap.Format.BitsPerPixel + 7) / 8), 0);

            return bitmap;
        }

 

BitmapSource

标签:private   orm   div   vat   height   style   copy   for   str   

原文地址:https://www.cnblogs.com/RedSky/p/12040309.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!