How to close this stream ?

async Task<StorageFile> CropImage(StorageFile storageFile, ImageCropper imageCropper)
{
var copiedStorageFile = await storageFile.CopyAsync(ApplicationData.Current.TemporaryFolder, storageFile.Name, NameCollisionOption.ReplaceExisting);
using (var fileStream = await copiedStorageFile.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
{
await imageCropper.SaveAsync(fileStream, BitmapFileFormat.Png);
}
return copiedStorageFile;
}
async Task<StorageFile> CropImage(StorageFile storageFile, ImageCropper imageCropper)
{
var copiedStorageFile = await storageFile.CopyAsync(ApplicationData.Current.TemporaryFolder, storageFile.Name, NameCollisionOption.ReplaceExisting);
using (var fileStream = await copiedStorageFile.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.None))
{
await imageCropper.SaveAsync(fileStream, BitmapFileFormat.Png);
}
return copiedStorageFile;
}
5 Replies
333fred
333fred2y ago
Whch stream? The fileStream? If so, the using will take care of that for you
TotechsStrypper
When I reuse the crop image it said being used by other process
The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)
The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)
Becquerel
Becquerel2y ago
are you sure you're not getting that error from trying to open the file?
TotechsStrypper
ah no it's from the CopyAsync when trying to crop the same image
Susko3
Susko32y ago
Try changing the temp file name, mange the old name with a Guid.NewGuid
Want results from more Discord servers?
Add your server
More Posts