Get Bytes From BitmapSource

image_pdfimage_print
   
 

/*
 License:  Microsoft Public License (Ms-PL)  
 http://c4fdevkit.codeplex.com/license
 C4F Developer Kit

*/
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Media.Imaging;

public class MainClass{

        static byte[] GetBytesFromBitmapSource(BitmapSource bmp)
        {
            int width = bmp.PixelWidth;
            int height = bmp.PixelHeight;
            int stride = width * ((bmp.Format.BitsPerPixel + 7) / 8);

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

            bmp.CopyPixels(pixels, stride, 0);

            return pixels;
        }
}

   
     


This entry was posted in 2D Graphics. Bookmark the permalink.