public bool Convert(Bitmap bmp) // can call independent of watcher { OutputFilename = null; FinalSize = Point.Empty; Converted = false; if (!GetOutputSubFolder()) { Controller.LogLineHighlight("Cannot convert " + InputExtension + " into the same folder as they are stored into" + Environment.NewLine + Environment.NewLine + "Pick a different conversion folder or a different output format"); return(false); } if (OutputFilename == null || ReConvert) { using (Bitmap croppedbmp = ConvertImage(bmp)) { if (OutputExtension.Equals(".jpg")) { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Jpeg); } else if (OutputExtension.Equals(".tiff")) { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Tiff); } else if (OutputExtension.Equals(".bmp")) { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Bmp); } else { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Png); } FinalSize = new Point(croppedbmp.Size); Converted = true; } } if (Converted) { File.SetCreationTime(OutputFilename, Timestamp); if (JournalScreenShot != null) { JournalScreenShot.SetConvertedFilename(InputFilename, OutputFilename, FinalSize.X, FinalSize.Y); } System.Diagnostics.Debug.WriteLine("Convert " + InputFilename + " at " + SystemName + " to " + OutputFilename); Controller.LogLine("Converted " + Path.GetFileName(InputFilename) + " to " + Path.GetFileName(OutputFilename)); } return(Converted); }
public bool Convert(Bitmap bmp, Action <string> logit) // can call independent of watcher, pass in bmp to convert { OutputFilename = null; FinalSize = Point.Empty; Converted = false; if (!UpdateOutputFolderWithSubFolder()) // add on any sub folder options to output folder { logit(string.Format(("Cannot convert {0} into the same folder as they are stored into" + Environment.NewLine + "Pick a different conversion folder or a different output format").Tx(this, "FolderErr"), InputFileExtension.ToString())); return(false); } using (Bitmap croppedbmp = ConvertImage(bmp)) // do the convert to BMP { if (OutputFileExtension == OutputTypes.jpg) { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Jpeg); } else if (OutputFileExtension == OutputTypes.tiff) { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Tiff); } else if (OutputFileExtension == OutputTypes.bmp) { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Bmp); } else { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Png); } FinalSize = new Point(croppedbmp.Size); Converted = true; } if (Converted) { File.SetCreationTime(OutputFilename, Timestamp); if (JournalScreenShot != null) { JournalScreenShot.SetConvertedFilename(InputFilename, OutputFilename, FinalSize.X, FinalSize.Y); } System.Diagnostics.Debug.WriteLine("Convert " + InputFilename + " at " + SystemName + " to " + OutputFilename); logit(string.Format("Converted {0} to {1}".Tx(this, "CNV"), Path.GetFileName(InputFilename), Path.GetFileName(OutputFilename))); } return(Converted); }
public bool Convert() // can call independent of watcher { OutputFilename = null; FinalSize = Point.Empty; Converted = false; FileInfo fi = null; if (JournalScreenShot != null) { CommanderID = JournalScreenShot.CommanderId; } using (Bitmap bmp = GetScreenshot(InputFilename, SystemName, CommanderID, ref JournalScreenShot, ref OutputFilename, ref FinalSize, ref fi)) { CommanderID = JournalScreenShot.CommanderId; // reload in case GetScreenshot changed it.. Timestamp = fi.CreationTimeUtc; if (!GetOutputSubFolder()) { Controller.LogLineHighlight("Cannot convert " + InputExtension + " into the same folder as they are stored into" + Environment.NewLine + Environment.NewLine + "Pick a different conversion folder or a different output format"); return(false); } if (OutputFilename == null || ReConvert) { using (Bitmap croppedbmp = ConvertImage(bmp)) { if (OutputExtension.Equals(".jpg")) { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Jpeg); } else if (OutputExtension.Equals(".tiff")) { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Tiff); } else if (OutputExtension.Equals(".bmp")) { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Bmp); } else { croppedbmp.Save(OutputFilename, System.Drawing.Imaging.ImageFormat.Png); } FinalSize = new Point(croppedbmp.Size); Converted = true; } } } if (Converted) { File.SetCreationTime(OutputFilename, fi.CreationTime); if (JournalScreenShot != null) { JournalScreenShot.SetConvertedFilename(InputFilename, OutputFilename, FinalSize.X, FinalSize.Y); } Controller.LogLine("Converted " + Path.GetFileName(InputFilename) + " to " + Path.GetFileName(OutputFilename)); } return(Converted); }
public bool Convert(Bitmap bmp, Action <string> logit) // can call independent of watcher, pass in bmp to convert { OutputFilename = null; FinalSize = Point.Empty; Converted = false; if (!UpdateOutputFolderWithSubFolder()) // add on any sub folder options to output folder { logit(string.Format(("Cannot convert {0} into the same folder as they are stored into" + Environment.NewLine + "Pick a different conversion folder or a different output format").T(EDTx.ScreenShotImageConverter_FolderErr), InputFileExtension.ToString())); return(false); } // bmp is the original bitmap at full res int index = 0; string bodyname = (JournalScreenShot.Body == null) ? "" : (JournalScreenShot.Body.Equals(SystemName, StringComparison.InvariantCultureIgnoreCase) ? "" : JournalScreenShot.Body); string secondfilename, thirdfilename; do // add _N on the filename for index>0, to make them unique. { string fn = CreateFileName(SystemName, bodyname, InputFilename, FilenameFormatIndex, HighRes, Timestamp) + (index == 0 ? "" : "_" + index); OutputFilename = Path.Combine(OutputFolder, fn + "." + OutputFileExtension.ToString()); secondfilename = Path.Combine(OutputFolder, fn + "-1." + OutputFileExtension.ToString()); thirdfilename = Path.Combine(OutputFolder, fn + "-2." + OutputFileExtension.ToString()); index++; } while (File.Exists(OutputFilename)); // if name exists, pick another // the OutputFilename should point to the best screenshot, and FinalSize points to this if (CropResizeImage1 == ScreenShotConverter.CropResizeOptions.Off || KeepMasterConvertedImage) // if resize 1 off, or keep full size. { WriteBMP(bmp, OutputFilename); FinalSize = new Point(bmp.Size); // this is our image to use in the rest of the system } if (CropResizeImage1 != ScreenShotConverter.CropResizeOptions.Off) { string nametouse = KeepMasterConvertedImage ? secondfilename : OutputFilename; // if keep full sized off, we use this one as our image if (CropResizeImage1 == ScreenShotConverter.CropResizeOptions.Crop) { Bitmap cropped = bmp.CropImage(CropResizeArea1); WriteBMP(cropped, nametouse); cropped.Dispose(); } else { Bitmap resized = bmp.ResizeImage(CropResizeArea1.Width, CropResizeArea1.Height); WriteBMP(resized, nametouse); resized.Dispose(); } if (!KeepMasterConvertedImage) // if not keeping the full sized one, its final { FinalSize = new Point(bmp.Size); } } if (CropResizeImage2 == ScreenShotConverter.CropResizeOptions.Crop) { Bitmap cropped = bmp.CropImage(CropResizeArea2); WriteBMP(cropped, thirdfilename); cropped.Dispose(); } else if (CropResizeImage2 == ScreenShotConverter.CropResizeOptions.Resize) { Bitmap resized = bmp.ResizeImage(CropResizeArea2.Width, CropResizeArea2.Height); WriteBMP(resized, thirdfilename); resized.Dispose(); } Converted = true; if (Converted) { if (JournalScreenShot != null) { JournalScreenShot.SetConvertedFilename(InputFilename, OutputFilename, FinalSize.X, FinalSize.Y); } System.Diagnostics.Debug.WriteLine("Convert " + InputFilename + " at " + SystemName + " to " + OutputFilename); logit(string.Format("Converted {0} to {1}".T(EDTx.ScreenShotImageConverter_CNV), Path.GetFileName(InputFilename), Path.GetFileName(OutputFilename))); } return(Converted); }