0
 BitmapImage bm = new BitmapImage(new Uri("/Assets/ToolKit.Content/RedIcon/arab-woman.jpg", UriKind.RelativeOrAbsolute));

 using (MemoryStream ms = new MemoryStream())
 {
      WriteableBitmap btmMap = new WriteableBitmap(bm);
      System.Windows.Media.Imaging.Extensions.SaveJpeg(btmMap, ms, bm.PixelWidth, bm.PixelHeight, 0, 100);
      bm = null;
      byte[] a = ms.ToArray();
 }

I am using this code but it showing error I cannot convert to WriteableBitmap.

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74

2 Answers2

0

You have an error because you didnt really download the image. If you open your BitmapImage in your debugger, I am pretty sure you can see that there is nothing here. You can force the download by using an Image. I dont know if it is a great solution, but it is a working solution.

Image image = new Image {Source = new BitmapImage(new Uri("/Assets/ToolKit.Content/RedIcon/arab-woman.jpg", UriKind.Relative))};
using (MemoryStream ms = new MemoryStream())
{
    WriteableBitmap btmMap = new WriteableBitmap(image, null);
    btmMap.SaveJpeg(ms, btmMap.PixelWidth, btmMap.PixelHeight, 0, 100);
    byte[] a = ms.ToArray();
}
aloisdg
  • 22,270
  • 6
  • 85
  • 105
0

You can use the following code to convert bitmap image to byte array

byte[] a = System.IO.File.ReadAllBytes("Assets\\ToolKit.Content\\RedIcon\\arab-woman.jpg");
Charan Ghate
  • 1,384
  • 15
  • 32