Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What should come here:
C#
private byte[] ConvertToBytes(Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage)
{
  ???
}


If someone has a working solution please share with me.
Posted
Updated 25-Jul-13 23:59pm
v2

HI Sogorka,

If I understand your question correct,here is the link to convert bitmap image to byte array.
Where as in the below link it converts and save it in database.But you need just conversion part.
Try that alone if you want.

And here is the link[^]

Hope this helps you a bit.

Thanks,
Rk
 
Share this answer
 
Comments
Waqas Ahmed Ansari 4-Apr-14 16:26pm    
I want to show the converted image in Image Box. But I am not able to show an image in there. This is the code I am using;

Service1Client GetNameFromService = new Service1Client();
GetNameRequest NameRequest = new GetNameRequest();
NameRequest.username = e.Parameter.ToString();
GetNameResponse NameResponse = await GetNameFromService.GetNameAsync(NameRequest);
lblName.Text = NameResponse.GetNameResult.NAME;
byte[] IMG = NameResponse.GetNameResult.IMAGE;


var stream = new InMemoryRandomAccessStream();
await stream.WriteAsync(IMG.AsBuffer());
stream.Seek(0);

BitmapImage image = new BitmapImage();
image.SetSource(stream);
imgUser.Source = image;

ID = NameResponse.GetNameResult.id;

await GetNameFromService.CloseAsync();
I found an alternate way to get the result as a byte[] or a BitmapImage as follows:

C#
private async Task DownloadUrlAsync(string url)
{
  byte[] ByteResult = null;
  BitmapImage BitmapResult = new BitmapImage();
  ImageSource ImageSourceResult = null;
  if (!string.IsNullOrEmpty(url))
  {
    HttpClient client = new HttpClient();
    ByteResult = await client.GetByteArrayAsync(url);  //result as: byte[]
    InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
    await ras.WriteAsync(ByteResult.AsBuffer());
    ras.Seek(0);
    BitmapResult.SetSource(ras);
    ImageSourceResult = BitmapResult;  //result as: ImageSource or BitmapImage
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900