BitmapSource must be converted into Bitmap. ..
Using System; using System. drawing; using System. drawing. imaging; using System. windows; using System. windows. media. imaging; namespace Jisons {public static class BitmapSourceHelper {public static Bitmap ConvertToBitmap (this BitmapSource bs) {return ConvertToBitmap (bs, 0, 0, bs. pixelWidth, bs. pixelHeight);} public static Bitmap ConvertToBitmap (this BitmapSource bs, int x, int y, int width, int height) {var bmp = new Bitmap (width, height, PixelFormat. format32bppPArgb); var bmp data = bmp. lockBits (new Rectangle (System. drawing. point. empty, bmp. size), ImageLockMode. writeOnly, PixelFormat. format32bppPArgb); bs. copyPixels (new Int32Rect (x, y, width, height), BMP data. scan0, BMP data. height * BMP data. stride, BMP data. stride); bmp. unlockBits (bmp data); return bmp;} public static byte [] ConvertToBytes (this BitmapSource bs) {return ConvertToBytes (bs, 0, 0, (int) bs. width, (int) bs. height);} public static byte [] ConvertToBytes (this BitmapSource bs, int x, int y, int width, int height) {var rect = new Int32Rect (x, y, width, height); var stride = bs. format. bitsPerPixel * rect. width/8; byte [] data = new byte [rect. height * stride]; bs. copyPixels (rect, data, stride, 0); return data;} public static BitmapSource ClipBitmapSource (this BitmapSource bs, int x, int y, int width, int height) {var rect = new Int32Rect (x, y, width, height); var stride = bs. format. bitsPerPixel * rect. width/8; byte [] data = new byte [rect. height * stride]; bs. copyPixels (rect, data, stride, 0); return BitmapSource. create (width, height, 0, 0, System. windows. media. pixelFormats. bgra32, null, data, stride);} public static Bitmap ConvertToBitmap (this byte [] data, int width, int height) {var bmp = new Bitmap (width, height ); for (int w = 0; w <width; w ++) {for (int h = 0; h View Code
BitmapSource convertings Bitmap