I have files with this structure
+-------------+-------------+---------------+---------+-------------+
| img1_offset | img1_length | Custom Info | Image 1 | Image 2 |
+-------------+-------------+---------------+---------+-------------+
Now I want to read Image 1
to image control. One possible way is open this file in a stream (fileStream
), copy image 1 part to other stream (i1_Stream
) then read image from i1_Stream
. Code I'm using:
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (MemoryStream i1_Stream = new MemoryStream())
{
fileStream.Seek(500, SeekOrigin.Begin); // i1_offset
fileStream.CopyTo(i1_Stream, 30000); // i1_length
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = i1_Stream;
bitmap.EndInit();
return bitmap;
}
}
Because I need open many file like this at one time (ie. load 50 images from 50 files to WrapPanel), I think it is better if I can read Image 1
directly from fileStream
. How I can do that? Thank!