timelapsenow/TimelapseApi/ExportForm.cs

82 lines
1.9 KiB
C#
Raw Normal View History

2022-05-20 02:06:35 +00:00
using System.Collections;
using Eto.Forms;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
namespace TimelapseApi;
internal class ExportForm :Form, IEnumerator<Image<Rgb24>> , IEnumerable<Image<Rgb24>>
{
int _i=-1;
int i {get {return _i;} set{bar.Value=value+1; bar.Invalidate(); _i=value; }}
int count;
ProgressBar bar;
Button cancel;
CancellationTokenSource src;
TimelapseProject _proj;
public ExportForm(TimelapseProject proj,CancellationTokenSource token)
{
Width=258; Height=73;
Title="Exporting";
_proj=proj;
src=token;
bar=new ProgressBar {MaxValue=proj.FrameCount,MinValue=0};
cancel=new Button {Text = "Cancel"};
count=proj.FrameCount;
DynamicLayout lyt=new DynamicLayout();
lyt.BeginVertical();
lyt.BeginHorizontal();
lyt.Add(bar,true);
lyt.EndHorizontal();
lyt.EndBeginVertical();
lyt.AddSpace(true,true);
lyt.BeginHorizontal();
lyt.AddSpace(true);
lyt.Add(cancel);
lyt.EndHorizontal();
lyt.EndVertical();
Content=lyt;
}
private Image<Rgb24> GetImage()
{
if(_proj.ProjectLocation==null)
{
return new Image<Rgb24>(1280,720);
}
using(var s=_proj.ProjectLocation.Open($"Sections/{_proj.SectionName}/{i}.png",FileMode.Open,FileAccess.Read,FileShare.Read))
{
return Image.Load<Rgb24>(s);
}
}
public Image<Rgb24> Current {
get {
return GetImage();
}
}
object IEnumerator.Current {get{return Current;}}
public IEnumerator<Image<Rgb24>> GetEnumerator()
{
return this;
}
public bool MoveNext()
{
return ++i < count;
}
public void Reset()
{
i=-1;
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}