A list of files (pictures) can be searched and shown in listbox

This commit is contained in:
2020-08-02 23:28:42 +02:00
parent 6949a7ba33
commit 4e56dadd25
8 changed files with 236 additions and 10 deletions

View File

@ -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;
}
}
}

View File

@ -0,0 +1,63 @@

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using ImageHandlingLibrary.InterFaces;
namespace ImageHandlingLibrary.Helpers
{
public class Dialogs : IDialogs
{
public List<FileInfo> ChooseFiles()
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
var outPut = new List<FileInfo>();
ofd.Title = "Välj bild-fil!";
ofd.InitialDirectory = "C:\\";
ofd.Filter = "Picture files (*.jpg)|*.jpg;*.jpeg|All files (*.*)|*.*";
ofd.FilterIndex = 1;
ofd.RestoreDirectory = true;
ofd.Multiselect = true;
ofd.ShowDialog();
var fnames = ofd.FileNames;
if (fnames.Length > 1)
{
foreach (var fname in fnames)
{
outPut.Add(new FileInfo(fname));
}
}
//else
//{
// string fName = ofd.FileName;
// if (fName.Trim() != "")
// {
// int fNamePos = fName.LastIndexOf(@"\") + 1;
// lblFileName.Text = fName.Substring(fNamePos);
// lblPath.Text = fName.Substring(0, fNamePos);
// listLocalFiles();
// for (int i = 0; i < lstPicFiles.Items.Count; i++)
// {
// if (lstPicFiles.Items[i].ToString() == lblFileName.Text)
// {
// lstPicFiles.SelectedIndex = i;
// break;
// }
// }
// }
//}
return outPut;
}
}
}
}

View File

@ -32,9 +32,11 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -45,6 +47,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Filing.cs" />
<Compile Include="Helpers\Dialogs.cs" />
<Compile Include="InterFaces\IDialogs.cs" />
<Compile Include="InterFaces\IFiling.cs" />
<Compile Include="InterFaces\IRegistring.cs" />
<Compile Include="Models\LocalPicture.cs" />

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImageHandlingLibrary.InterFaces
{
public interface IDialogs
{
List<FileInfo> ChooseFiles();
}
}

View File

@ -1,6 +1,8 @@
using System;
using ImageHandlingLibrary.Models;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -11,6 +13,9 @@ namespace ImageHandlingLibrary.InterFaces
public interface IFiling
{
BitmapImage ConvertFromDrawImage(Image _image);
List<LocalPicture> CreateListBoxDataSource(List<FileInfo> fileInfos, string rootCatalog);
string ShowText();
}
}