Silverlight中将WriteableBitmap互转byte数组

时间:2023-12-04 20:24:50
//WriteableBitmap to ARGB byte array
public static byte[] ToByteArray(this WriteableBitmap bmp)
{
   int[] p = bmp.Pixels;
   int len = p.Length * ;
   byte[] result = new byte[len]; // ARGB
   Buffer.BlockCopy(p, , result, , len);
   return result;
} //Copy ARGB byte array into WriteableBitmap
public static void FromByteArray(this WriteableBitmap bmp, byte[] buffer)
{
   Buffer.BlockCopy(buffer, , bmp.Pixels, , buffer.Length);
}