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; using System.Text; using System.Threading.Tasks; using System.Windows.Media.Imaging; namespace ImageHandlingLibrary { public class Filing : IFiling { private readonly IRegistring _registring; public Filing(IRegistring registring) { _registring = registring; } public BitmapImage ConvertFromDrawImage(System.Drawing.Image _image) { using (var ms = new MemoryStream()) { //System.Drawing.Image.FromFile(@"D:\CsharpDevelop\PictureHandlingProject\pictures\AgueroVillage.JPG").Save(ms, ImageFormat.Bmp); _image.Save(ms, ImageFormat.Bmp); ms.Seek(0, SeekOrigin.Begin); var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.StreamSource = ms; bitmapImage.EndInit(); return bitmapImage; } } public string ShowText() { var output = _registring.GetRegistryRootDir(); return $"Root directory value is {output} OBS Test!!"; } public List CreateListBoxDataSource(List fileInfos, string rootCatalog) { var outPut = new List(); 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 FillupDateGaps(List inPut) { var picReg = new SortedList(); foreach (var pict in inPut) { picReg.Add(pict.PictureFileName, pict); } var tmpPicture = new LocalPicture(); tmpPicture.CreatedDate = ""; Stack stack = new Stack(); var outPut = new List(); foreach (KeyValuePair 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; } } }