private void ShowGallerySelectionImages(TheImage obj) { if (imglist.LargeImageList != null && imglist.LargeImageList.Images.Count > 0) { imglist.LargeImageList.Images.Clear(); } SelectedImageKeys.Clear(); imglist.Clear();//imglist.LargeImageList.Images.Clear(); imageIO.CreateImageListFromThumbnails(obj, imgs); imglist.LargeImageList = imgs; CheckForMaxImageWarning(); foreach (var item in obj.PeerImages) { //SelectImage(item); // image key is the image sleected from imagelist collection, key must present in imagelist above //var lvitem = new ListViewItem(item.ImageName, item.ImageKey); //SelectedImageChecked(lvitem); imglist.Items.Add(item.ImageName, item.ImageKey); } foreach (ListViewItem item in imglist.Items) { SelectImage(item); } imglist.Show(); }
internal static void AdjustImageOrientation_A4(TheImage item, int exifOrientationID, ImageFactory imageFactory, PropertyItem prop) { //Image orientation is correct, remove orientation key, its not needed. if (imageFactory.Image.Width > imageFactory.Image.Height && prop != null) { imageFactory.Rotate(90); PropertyItem tval; imageFactory.ExifPropertyItems.TryRemove(exifOrientationID, out tval); imageFactory.Save(item.ImageFullName); } if (imageFactory.Image.Width > imageFactory.Image.Height && prop == null) { imageFactory.Rotate(90); imageFactory.Save(item.ImageFullName); } //Rotate image, remove orientation key, its not needed. if (imageFactory.Image.Width < imageFactory.Image.Height && prop != null) { //imageFactory.Rotate(90); PropertyItem tval; imageFactory.ExifPropertyItems.TryRemove(exifOrientationID, out tval); imageFactory.Save(item.ImageFullName); } //Rotate image, no orientation key //else if (imageFactory.Image.Width < imageFactory.Image.Height && prop == null) //{ // //imageFactory.Rotate(90); // imageFactory.Save(item.ImageFullName); //} }
private void ReportProgressForImageSearch(TheImage obj) { foundImageCount = (foundImageCount + obj.ImageDirTotalImages); //TODO : write here invoke required and invoke to display images found count on form //if(InvokeRequired) // Invoke(new Action(() => label13.Text = foundImageCount.ToString() + " images found")); AllImages.Add(obj); }
private void ShowGallerySelectionImages(TheImage obj) { imglist.Clear(); CreateImageList(obj); imglist.LargeImageList = imgs; foreach (var item in obj.PeerImages) { // image key is the image sleected from imagelist collection, key must present in imagelist above imglist.Items.Add(item.ImageName, item.ImageKey); imglist.Show(); } imgs.Images.Add(obj.ImageKey, Image.FromFile(obj.ImageFullName).GetThumbnailImage(200, 200, null, IntPtr.Zero)); imgs.ImageSize = new Size(200, 200); imglist.Items.Add(obj.ImageName, obj.ImageKey); imglist.Show(); }
private void CreateImageList(TheImage obj) { imgs.ImageSize = new Size(200, 200); imgs.ColorDepth = ColorDepth.Depth32Bit; List <Image> images = new List <Image>(); foreach (var item in obj.PeerImages) { using (Image im = Image.FromFile(item.ImageFullName)) { //images.Add(); var imtemp = ResizeImage(im, 200, 200); imgs.Images.Add(item.ImageKey, imtemp); //im.Dispose();// = null; } } }
private void ShowDirectory(TheImage obj) { Button btn = (new Button() { Text = obj.ImageDirName + " (" + obj.ImageDirTotalImages + ")", TextImageRelation = TextImageRelation.ImageBeforeText, Size = new Size(120, 52), AutoSizeMode = AutoSizeMode.GrowAndShrink, TextAlign = ContentAlignment.MiddleLeft, FlatStyle = FlatStyle.Popup, BackColor = Color.White, Image = new Bitmap("..\\..\\..\\pics\\vst.png"), ImageAlign = ContentAlignment.TopLeft, Tag = obj }); btn.Click += DirectoryButtonClick; folder_list.Controls.Add(btn); }
void ReleaseDesignerOutlets() { if (TheImage != null) { TheImage.Dispose(); TheImage = null; } if (FullNameLabel != null) { FullNameLabel.Dispose(); FullNameLabel = null; } if (DescriptionLabel != null) { DescriptionLabel.Dispose(); DescriptionLabel = null; } }
public void ReDrawRooms() { // Clear Fill(Color.Black); Graphics g = Graphics.FromImage(TheImage); DrawGrid(g); // Rooms foreach (Room room in Rooms) { TheImage.DrawOnto(room.RoomImage, room.DrawLocation); } // Border g.DrawRectangle(Pens.Red, new Rectangle(GRID_SIZE, GRID_SIZE, GRID_SIZE * MAP_SIZE, GRID_SIZE * MAP_SIZE)); g.Dispose(); }
private void ImageCovertHEICToJPG_WriteBackToSameFile(TheImage HEICimagePath) { if (!Path.GetExtension(HEICimagePath.ImageFullName).ToLower().Contains("heic")) { return; } byte[] photoBytes = File.ReadAllBytes(HEICimagePath.ImageFullName); using (MemoryStream inStream = new MemoryStream(photoBytes)) { using (MagickImage image = new MagickImage(inStream, MagickFormat.Heic)) { //string FileName = Path.GetFileNameWithoutExtension(HEICimagePath.ImageFullName); image.Write(HEICimagePath.ImageFullName, MagickFormat.Jpg); string prevName = HEICimagePath.ImageFullName; //Now change name in collection HEICimagePath.ImageFullName = Path.ChangeExtension(HEICimagePath.ImageFullName, ".jpg"); HEICimagePath.ImageName = Path.GetFileName(HEICimagePath.ImageFullName); //Rename physical file. File.Move(prevName, HEICimagePath.ImageFullName); } } }
internal void CreateImageListFromThumbnails(TheImage obj, ImageList imgs) { if (ConfigurationManager.AppSettings["Mode"] == "Diagnostic") { logger.Log(NLog.LogLevel.Info, "Inside CreateImageListFromThumbnails function"); } imgs.ImageSize = new Size(200, 200); imgs.ColorDepth = ColorDepth.Depth32Bit; List <Image> images = new List <Image>(); foreach (var item in obj.PeerImages) { if (File.Exists(item.ImageThumbnailFullName)) { using (Image im = Image.FromFile(item.ImageThumbnailFullName)) { //images.Add(); var imtemp = ResizeImage(im, 200, 200); imgs.Images.Add(item.ImageKey, imtemp); //im.Dispose();// = null; } } } }
//} internal async Task Wifi_PostProcessImages(TheImage ImageDir, bool forceCreateAll = false) { if (ConfigurationManager.AppSettings["Mode"] == "Diagnostic") { logger.Log(NLog.LogLevel.Info, "Inside Wifi_RotateImageIfNeeded_CreateThumbnails function"); } int count = 0; Image tempImg = null; Image thmImg = null; await Task.Run(() => { //ResizeImagesIfNeeded(ImageDir); //Lets try and create thumbnails foreach (var item in ImageDir.PeerImages) { if (forceCreateAll == false && Directory.Exists(item.ImageDirName) && File.Exists(item.ImageThumbnailFullName)) { continue; //thumbnail already exists , skip } else if (!Directory.Exists(item.ImageDirName)) { Directory.CreateDirectory(item.ImageDirName); } try { if (Globals.PrintSelection == Globals.PrintSize.pdf && item.ImageName.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase)) { //For PDFs, copy a readymade icon file of pdf. File.Copy(Globals.pdfIcon, item.ImageThumbnailFullName); //replaces thumbnail .jpg ext. } else { ImageCovertHEICToJPG_WriteBackToSameFile(item); (new ImageResizing(item.ImageFullName)).ResizeIfNeeded(item.ImageFullName); int exifOrientationID = 0x112; byte[] photoBytes = File.ReadAllBytes(item.ImageFullName); using (MemoryStream inStream = new MemoryStream(photoBytes)) { using (MemoryStream outStream = new MemoryStream()) { // Initialize the ImageFactory using the overload to preserve EXIF metadata. using (ImageFactory imageFactory = new ImageFactory(preserveExifData: true)) { // Load, resize, set the format and quality and save an image. imageFactory.Load(inStream); thmImg = imageFactory.Image.GetThumbnailImage(200, 200, null, IntPtr.Zero); using (var fs = new FileStream(item.ImageThumbnailFullName, FileMode.Create)) { //fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length); thmImg.Save(fs, ImageFormat.Jpeg); } PropertyItem prop; thmImg.Save(item.ImageThumbnailFullName, ImageFormat.Jpeg); //memAvailable = System.GC.GetTotalMemory(false); imageFactory.ExifPropertyItems.TryGetValue(exifOrientationID, out prop); if (Globals.PrintSelection == Globals.PrintSize.A5) { AdjustImageOrientation_A5(item, exifOrientationID, imageFactory, prop); } else if (Globals.PrintSelection == Globals.PrintSize.A4) { AdjustImageOrientation_A4(item, exifOrientationID, imageFactory, prop); } else if (Globals.PrintSelection == Globals.PrintSize.Passport) { //Will work for passport as well AdjustImageOrientation_A4(item, exifOrientationID, imageFactory, prop); } else if (Globals.PrintSelection == Globals.PrintSize.Postcard) { //will work for postcard as well AdjustImageOrientation_A5(item, exifOrientationID, imageFactory, prop); } //memAvailable = GetMemoryUsage(); } // Do something with the stream. } } } } catch (OutOfMemoryException o) { logger.Log(NLog.LogLevel.Error, o.Message + "Inner ex:" + o.InnerException.Message); } catch (Exception e) { //TODO: Log e logger.Log(NLog.LogLevel.Error, e.Message + "Inner ex:" + e.InnerException.Message); } finally { if (tempImg != null) { tempImg.Dispose(); } if (thmImg != null) { thmImg.Dispose(); } } count++; } }); //imgs.Images.Add(obj.ImageKey, Image.FromFile(obj.ImageFullName).GetThumbnailImage(250, 250, null, IntPtr.Zero)); }
internal async Task DirectConn_CreateThumbnails(TheImage ImageDir) { await Wifi_PostProcessImages(ImageDir); }
//private void Done(bool IsWeb) //{ // imageIO.BubbleSortImages(AllImages); // //Bubble sort Images // //for (int write = 0; write < AllImages.Count; write++) // //{ // // for (int sort = 0; sort < AllImages.Count - 1; sort++) // // { // // if (AllImages[sort].ImageDirTotalImages > AllImages[sort + 1].ImageDirTotalImages) // // { // // var temp = AllImages[sort + 1]; // // AllImages[sort + 1] = AllImages[sort]; // // AllImages[sort] = temp; // // } // // } // //} // foreach (var item in AllImages) // { // //Create Thumbnails // Task task = new Task(async () => // { // await imageIO.DirectConn_CreateThumbnails(item); // }); // task.Start(); // ReportProgressForThumbnails(item.ImageDirName); // } // AllImages.Reverse(); // waiter.Close(); // if (IsWeb) // { // SimpleGallery gallery = new SimpleGallery(); // gallery.AllImages = AllImages; // gallery.Show(); // } // else // { // DirectoryGallery gallery = new DirectoryGallery(); // gallery.AllImages = AllImages; // gallery.Show(); // } //} //TODO: group methods and write comments // //imgs.Images.Add(obj.ImageKey, Image.FromFile(obj.ImageFullName).GetThumbnailImage(250, 250, null, IntPtr.Zero)); //} private void ReportProgressForImageSearch(TheImage obj) { foundImageCount = (foundImageCount + obj.ImageDirTotalImages); waiter.FileFoundLabelText = foundImageCount.ToString() + " images found"; AllImages.Add(obj); }