Chirag
Chirag

Reputation: 475

Convert BitmapImage to Byte[] in Silverlight4

can any one has idea. how to convert BitmapImage to Byte[] in silverlight4 application i have one image file in .xap file.

BitmapImage bi = new BitmapImage(new Uri("images/GRed.png", UriKind.Relative));

now i want to convert BitmapImage to Byte[] and save in to db as binary format.

Upvotes: 1

Views: 2834

Answers (1)

tsiorn
tsiorn

Reputation: 2236

    private byte[] ToByteArray(BitmapImage bi)
    {
        WriteableBitmap bmp = new WriteableBitmap(bi);
        int[] p = bmp.Pixels;
        int len = p.Length * 4;
        byte[] result = new byte[len]; 
        Buffer.BlockCopy(p, 0, result, 0, len);
        return result;
    }

Upvotes: 1

Related Questions