c# - Can I get a byte[] from a BitmapImage in Silverlight? -
I am trying to represent something behind the image between the Silverlight and WCF service. If possible, I want to pass the System.Windows.Media.imaging.BitmapImage
, this means that the client does not have to make any conversions.
However, at some point I need to store this image in a database, which means that the image representation should be able to change from byte []
. I can read the array in MemoryStream
and create BitmapImage
by byte []
using BitmapImage.SetSource (). I / code >. But I can not find any way to change - from bitmapImage
to byte []
on the other side. Do I have something clear here?
If it helps at all, the conversion code can run on the server, i.e. it does not need to be silly-secure.
Use this:
public byte [] GetBytes (bitmap) Image bi) {intelligent bitcake wbm = new writable bitmap); Return wbm.ToByteArray (); }
Where
public static byte [] ToByteArray (The WriteableBitmap BMP) {// Init buffer int w = bmp.PixelWidth; Int h = bmp.PixelHeight; Int [] P = BMP.Pixels; Int len = p.Length; Byte [] results = new byte [4 * w * h]; // Copy the buffer for buffer (int i = 0, j = 0; i > 24); // a result [j + 1] = (byte) (color> gt;> 16); // R results [j + 2] = (byte) (color>> 8); // live results [j + 3] = (byte) (color); // B} return result; }
Comments
Post a Comment