且构网

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

将byte[]转为WriteableBitmap对象

更新时间:2021-10-21 13:10:05

原文:将byte[]转为WriteableBitmap对象

//convert the bytes to WriteableBitmap

privateWriteableBitmap BytesToImage(byte[] src, int lw, int lh)

{

WriteableBitmap wbbitmap = newWriteableBitmap(lw, lh);

Stream s = wbbitmap.PixelBuffer.AsStream();

s.Seek(0, SeekOrigin.Begin);

s.Write(src, 0, lw * lh * 3);

return wbbitmap;

}

注:这里默认的WriteableBitmap对象为24位位图对象,如果是32位,则由流写入byte[]的时候要写为lw*lh*4。