I need to open all frames from Tiff image in WPF into memory and then delete the source. And after that I eventually need to render that image (resized according to window size). My solution is quite slow and I cannot delete file source before the first require. Any best practices?
相关问题
- VNC control for WPF application
- What uses more memory in c++? An 2 ints or 2 funct
- Memory for python.exe on Windows 7 python 32 - Num
- WPF Binding from System.Windows.SystemParameters.P
- Scaling of the point sprites (Direc3D 9)
I figured it out. I have to use MemoryStream:
Use
CacheOption = BitmapCacheOption.OnLoad
This option can be used with the
BitmapImage.CacheOption
property or as an argument toBitmapDecoder.Create()
If you want to access multiple frames once the images is loaded you'll have to useBitmapDecoder.Create
. In either case the file will be loaded fully and closed.See also my answer to this question
Update
The following code works perfectly for loading in all the frames of an image and deleting the file:
You can also access decoder.Frames after the file is deleted, of course.
This variant also works if you prefer to open the stream yourself:
In either case it is more efficient than creating a
MemoryStream
because aMemoryStream
keeps two copies of the data in memory at once: The decoded copy and the undecoded copy.