ipid
ipid

Reputation: 253

How to read image from PostAsync (HttpClient)?

How do I read images into ImageSource? The source I'm suppose to get from this Get method is a jpg file, which I want to put in ImageSource and return it.

This is how I normally get my Json data:

   var getJson = await client.GetAsync(myUrl).ConfigureAwait(false);

            if (getJson.IsSuccessStatusCode)
            {
                var json = await getJson.Content.ReadAsStringAsync().ConfigureAwait(false);

                return json
            }

Upvotes: 0

Views: 1527

Answers (1)

Amit Kumar Ghosh
Amit Kumar Ghosh

Reputation: 3726

you could try this -

var bytes = await getJson.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
MemoryStream ms = new MemoryStream(bytes);
Image returnImage = Image.FromStream(ms);

Upvotes: 2

Related Questions