I make some application which edit photo and save it in other location. So I find a question which shows how to resize photos in Windows Store Apps. Then I implement it in my program:
private async void ResizeButton_Click(object sender, RoutedEventArgs e)
{
uint width, height;
if (uint.TryParse(WidthTextBox.Text, out width) && uint.TryParse(HeightTextBox.Text, out height)
&& _folderWithPhoto != null && _targetFolder != null)
//_folderWithPhoto and _targetFolder are StorageFolder values get from FolderPicker
{
var files = await _folderWithPhoto.GetFilesAsync();
foreach (StorageFile item in files)
{
if (item.ContentType.Contains("image"))
{
StorageFile targetFile = await item.CopyAsync(_targetFolder, item.Name, NameCollisionOption.GenerateUniqueName);
var fileStream = await targetFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);
InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(ras, decoder);
enc.BitmapTransform.ScaledHeight = height;
enc.BitmapTransform.ScaledWidth = width;
await enc.FlushAsync();
}
}
}
}
Problem
Result of this code is the same photo saved in _targetFolder
catalogue. So I have no idea how to fix it.
Any help would be appreciated.