Dim b As StorageFile = Await a If b IsNot Nothing Then Dim d As BitmapEncoder = Await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, Await b.OpenAsync(FileAccessMode.ReadWrite)) d.SetSoftwareBitmap(c) Call d.FlushAsync() End If
This code runs normally for the first time. However, if the user chooses the same image file to save for the second time, meaning to replace it, the code fails because the previously opened stream was never closed. I didn't find any relevant methods to close the stream, or documents talking about it.
If the user closes the whole app, windows will forcibly close the stream. However, if the user makes another smaller image to save in the same file, then, after closing the whole app, the file still remains the previous larger size, and will never become smaller as the actual image data did.