A list of files (pictures) can be searched and shown in listbox
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
using ImageHandlingLibrary.InterFaces;
|
||||
using ImageHandlingLibrary.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -41,5 +43,93 @@ namespace ImageHandlingLibrary
|
||||
var output = _registring.GetRegistryRootDir();
|
||||
return $"Root directory value is {output} OBS Test!!";
|
||||
}
|
||||
|
||||
public List<LocalPicture> CreateListBoxDataSource(List<FileInfo> fileInfos, string rootCatalog)
|
||||
{
|
||||
|
||||
var outPut = new List<LocalPicture>();
|
||||
|
||||
foreach (var fi in fileInfos)
|
||||
{
|
||||
var bufPicture = new LocalPicture();
|
||||
|
||||
bufPicture.RootPosition = rootCatalog;
|
||||
|
||||
bufPicture.PictureFileName = fi.Name;
|
||||
|
||||
bufPicture.InitialPath = fi.DirectoryName;
|
||||
|
||||
bufPicture.AktImage = Image.FromFile(bufPicture.PictureFullPath);
|
||||
|
||||
bufPicture.AktImWidth = bufPicture.AktImage.Width;
|
||||
bufPicture.AktImHeight = bufPicture.AktImage.Height;
|
||||
|
||||
bufPicture.CreatedDate = TakenDate(bufPicture.AktImage);
|
||||
|
||||
outPut.Add(bufPicture);
|
||||
}
|
||||
|
||||
|
||||
return FillupDateGaps(outPut);
|
||||
}
|
||||
|
||||
private string TakenDate(Image aktImage)
|
||||
{
|
||||
string sPropDatTaken = "";
|
||||
for (int i = 0; i < aktImage.PropertyIdList.Length; i++)
|
||||
{
|
||||
if (aktImage.PropertyIdList[i] == 306)
|
||||
{
|
||||
for (int j = 0; j < aktImage.PropertyItems[i].Len; j++)
|
||||
{
|
||||
sPropDatTaken += Convert.ToChar(aktImage.PropertyItems[i].Value[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sPropDatTaken;
|
||||
}
|
||||
|
||||
private List<LocalPicture> FillupDateGaps(List<LocalPicture> inPut)
|
||||
{
|
||||
var picReg = new SortedList<string, LocalPicture>();
|
||||
foreach (var pict in inPut)
|
||||
{
|
||||
picReg.Add(pict.PictureFileName, pict);
|
||||
}
|
||||
var tmpPicture = new LocalPicture();
|
||||
tmpPicture.CreatedDate = "";
|
||||
Stack<string> stack = new Stack<string>();
|
||||
var outPut = new List<LocalPicture>();
|
||||
|
||||
foreach (KeyValuePair<string, LocalPicture> lPic in picReg)
|
||||
{
|
||||
if (lPic.Value.CreatedDate == "")
|
||||
{
|
||||
if (tmpPicture.CreatedDate != "")
|
||||
{
|
||||
lPic.Value.CreatedDate = tmpPicture.CreatedDate;
|
||||
lPic.Value.CreatedDateChanged = true;
|
||||
outPut.Add(lPic.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
stack.Push(lPic.Key);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpPicture = lPic.Value;
|
||||
while (stack.Count > 0)
|
||||
{
|
||||
var picRegKey = stack.Pop();
|
||||
picReg[picRegKey].CreatedDate = tmpPicture.CreatedDate;
|
||||
picReg[picRegKey].CreatedDateChanged = true;
|
||||
outPut.Add(picReg[picRegKey]);
|
||||
}
|
||||
outPut.Add(lPic.Value);
|
||||
}
|
||||
}
|
||||
return outPut;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user