locked
Image is not displaying in Image box

    Question

  • I am retrieving an image from data base in the form of byte array and change it into image type. I am done with all, but this image is not displaying. Following is the code I am using to convert byte array into image and displaying it in image box.

                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());
                BitmapImage image = new BitmapImage();
                image.SetSource(stream);
                imgUser.Source = image;

    I don't know what is happening, every effort has gone waste... Seeking for help, thanks in advance

    Friday, April 11, 2014 7:07 PM

Answers

  • Probably it could be, but why do you want to convert byte to UTF8?

    I believe the code I provide should work, because I've successfully convert the byte array to image in my test environment.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, April 17, 2014 2:59 AM
    Moderator

All replies

  • Hi Waqas,

    Sorry to hear that, but I would ask you to do a self-check for following possibilities.

    1, Did you set the Width and Height for your image in XAML?

    2, BitmapImage in Windows Store App only accept few image format, if your image is not in that format, I have to say sorry.

      • Joint Photographic Experts Group (JPEG)
      • Portable Network Graphics (PNG)
      • bitmap (BMP)
      • Graphics Interchange Format (GIF)
      • Tagged Image File Format (TIFF)
      • JPEG XR
      • icons (ICO)

    3, Could you validate if your Web Service can successfully provide you any image stream.

    Hope helps

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, April 14, 2014 1:12 AM
    Moderator
  • Thanks a lot for responsing.

    1. I've set the both in XAML

    2. My image format is JPEG

    3. I confirmed many times, mu WebService is successfully returning all the bytes that I've used in my code.

    Still not working......

    Monday, April 14, 2014 7:53 PM
  • Ok, I assume your image byte array is correct, can you try following code?

    var bitmapImage = new BitmapImage(); var stream = new InMemoryRandomAccessStream(); await stream.WriteAsync(IMG.AsBuffer()); //reset the stream

    stream.Seek(0); bitmapImage.SetSource(stream); ...

    --James

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, April 15, 2014 8:26 AM
    Moderator
  • I converted Byte into UTF8, will there be any problem in it?
    Wednesday, April 16, 2014 9:36 AM
  • Probably it could be, but why do you want to convert byte to UTF8?

    I believe the code I provide should work, because I've successfully convert the byte array to image in my test environment.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, April 17, 2014 2:59 AM
    Moderator