I have this piece of code that retrieves a image from a webservice and saves it to a StorageFile
StorageFolder folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync(Constants.DataDirectory, CreationCollisionOption.OpenIfExists);
StorageFile imgFile;
using (var httpClient = new HttpClient { BaseAddress = Constants.baseAddress })
{
string token = App.Current.Resources["token"] as string;
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
using (var response2 = await httpClient.GetAsync("user/image?userId=" + id))
{
Stream imageStream = await response2.Content.ReadAsStreamAsync();
if (imageStream.Length != 0)
{
byte[] bytes = new byte[imageStream.Length];
imageStream.Read(bytes, 0, (int)imageStream.Length);
imgFile = await folder.CreateFileAsync(fname, CreationCollisionOption.ReplaceExisting);
await FileIO.WriteBytesAsync(imgFile, bytes); //i want the image bytes to be of a smaller version of the image at this point
}
return await response2.Content.ReadAsStringAsync();
}
}
I would like to know if there is a way to convert the image bytes[]
to a thumbnail version (50x50 for example) before writing them into the StorageFile
.