0
我有这样一段代码由web服务检索图像,并将其保存到StorageFile
调整大小图像 - 视窗8
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();
}
}
我会想知道是否有方法将图像bytes[]
转换为缩略图版本(例如50x50),然后将它们写入StorageFile
。
查看我在这里提供的解决方案:http://stackoverflow.com/questions/32792626/reduce-image-size-physical-and-dimensions-coming-from-httppostedfilebase-then – Lorek