How to Convert Image to Byte array format? RRS feed

  • Question

  • I am retrieving image from the server, But while sending image to server i need to convert image to byte[] format.

    Here is my function for likes upload:

    private async void like_Tapped(object sender, TappedRoutedEventArgs e)
              var item = (SampleDataItem)flipView.SelectedItem;
               lik = int.Parse(item.like);
               lik = lik + 1;
               likes = lik.ToString();
               TenAttributesDataModel update = await sc.UpdateMediaAsync(item.ID, App.glo.appid, App.glo.userid, item.Group.Name,data,App.glo.apptoken, App.glo.usertoken, item.subcat, item.Name, item.Description, item.Price, item.url, likes, field1, field1, field1, field1);
               like.Visibility = Visibility.Collapsed;
               unlike.Visibility = Visibility.Visible;
        catch (Exception)
        { }

    I can retrieve image using item.Image it is in image format,  I have to convert it byte[] format

     Please help me to solve this problem. Thank you in advance. 


    Tuesday, April 30, 2013 7:42 AM


All replies

  • Hi ,

    I have an example . The below code is supposed to read the file image which you have already and convert it to byte array

     var stream = await file.OpenReadAsync();

                      using (var dataReader = new DataReader(stream))
                          var bytes = new byte[stream.Size];
                          await dataReader.LoadAsync((uint)stream.Size);


    Tuesday, April 30, 2013 9:04 AM
  • Take a look at this post


    pradeep aj If it answers, then please mark it as answer 

    • Edited by Pradeep AJ Wednesday, May 1, 2013 5:38 PM
    • Proposed as answer by Jesse Jiang Thursday, May 2, 2013 3:06 AM
    • Marked as answer by Jesse Jiang Monday, May 6, 2013 5:42 AM
    Wednesday, May 1, 2013 5:02 PM