Witam
Napisałem prosty odtwarzacz GIF
public partial class MainWindow : Window
{
private int counter = 0;
private int imageCount = 0;
private System.Drawing.Image img;
public MainWindow()
{
InitializeComponent();
img = System.Drawing.Image.FromFile("C:\\Users\\kamiś\\Desktop\\file.gif");
imageCount = img.GetFrameCount(FrameDimension.Time);
if (imageCount <= 1)
{
MessageBox.Show("Nie ma piku");
}
else {
var delay = BitConverter.ToInt32(img.GetPropertyItem(20736).Value,0) * 10;
DispatcherTimer DT = new DispatcherTimer();
DT.Interval = TimeSpan.FromMilliseconds(delay);
DT.Tick += new EventHandler(Tick);
DT.Start();
}
}
private void Tick(Object sender, EventArgs e) {
if (counter ==imageCount) {
counter = 0;
}
img.SelectActiveFrame(FrameDimension.Time, counter);
GIF.Source = ConvertImageToBitmapImage(img);
counter++;
}
public BitmapImage ConvertImageToBitmapImage(System.Drawing.Image img) {
using (var memory = new MemoryStream()) {
img.Save(memory, ImageFormat.Png);
memory.Position = 0;
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memory;
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.EndInit();
return bitmapImage;
}
}
}
}
Niestety wydaje mi się, że GIF w moim odtwarzaczu pracuje delikatnie wolniej. I tutaj pojawia się moje pytanie. Czy poprawnie pobieram czas trwania klatki z ramki ? Chodzi o ten element kodu
var delay = BitConverter.ToInt32(img.GetPropertyItem(20736).Value,0) * 10;