且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将WriteableBitmap转为byte[]

更新时间:2022-09-27 18:47:39

原文:将WriteableBitmap转为byte[]

Win8 metro中的操作与之前的版本有所不同,因此作为一个新手,我将自己的一些问题解答记录了下来,希望与大家分享!!

下面是将WriteableBitmap转为byte[]的函数(默认的图像为24位RGB格式):

private byte[] WriteableBitmapToBytes(WriteableBitmap src)

{

Stream temp = src.PixelBuffer.AsStream();

byte[] tempBytes = new byte[src.PixelWidth * src.PixelHeight * 3];

for (int i = 0; i < tempBytes.Length; i++)

{

temp.Seek(i, SeekOrigin.Begin);

temp.Write(tempBytes, 0, tempBytes.Length);

}

temp.Dispose();

return tempBytes;

}

本文所写的所有程序都已成功实践,若有错误请大家留言更正,谢谢指教,共勉!!