void SetupFormats(RasterSaveDialog saveDialog) { saveDialog.FileFormatsList = new Leadtools.WinForms.CommonDialogs.File.RasterSaveDialogFileFormatsList(Leadtools.WinForms.CommonDialogs.File.RasterDialogFileFormatDataContent.User); saveDialog.FileFormatsList.Add(RasterDialogFileTypesIndex.Jpeg2000, RasterDialogBitsPerPixelDataContent.User); int[] saveBBP = new int[] { 8, 12, 16, 24, 32 }; for (int i = 0; i < saveBBP.Length; i++) { saveDialog.FileFormatsList[0].BitsPerPixelList.Add(RasterDialogFileTypesIndex.Jpeg2000, saveBBP[i], RasterDialogFileSubTypeDataContent.User); saveDialog.FileFormatsList[0].BitsPerPixelList[i].SubFormatsList.Add(RasterDialogFileTypesIndex.Jpeg2000, saveBBP[i], (int)RasterDialogJ2kSubTypesIndex.Jpeg2000File); saveDialog.FileFormatsList[0].BitsPerPixelList[i].SubFormatsList.Add(RasterDialogFileTypesIndex.Jpeg2000, saveBBP[i], (int)RasterDialogJ2kSubTypesIndex.Jpeg2000Stream); } }
private void _btnLEADFormats_Click(object sender, System.EventArgs e) { RasterSaveDialog saveDlg = new RasterSaveDialog(_codecs); saveDlg.EnableSizing = true; saveDlg.FileFormatsList = new RasterSaveDialogFileFormatsList(RasterDialogFileFormatDataContent.Default); if (saveDlg.ShowDialog(this) == DialogResult.OK) { _txtFileName.Text = saveDlg.FileName; _nativeBPP = saveDlg.BitsPerPixel; _imageLEADFormat = saveDlg.Format; } DialogResult = DialogResult.None; }
private void btnChooseSaveLocation_Click(object sender, EventArgs e) { using (RasterCodecs codecs = MainForm.GetRasterCodecs()) { RasterSaveDialog rsd = new RasterSaveDialog(codecs); rsd.FileFormatsList = new RasterSaveDialogFileFormatsList(RasterDialogFileFormatDataContent.Default); rsd.ShowFormatSubType = false; rsd.ShowBitsPerPixel = false; rsd.Title = "Save scan..."; if (rsd.ShowDialog(this) == DialogResult.OK) { txtSaveLocation.Text = rsd.FileName; format = rsd.Format; } UpdateScanEnabled(); } }
private void Acquire(bool cleanup) { try { if (!DemosGlobal.CheckKnown3rdPartyTwainIssues(this, _twainSession.SelectedSourceName())) { return; } // get the output file name and file format RasterSaveDialog dlg = new RasterSaveDialog(_codecs); dlg.Title = "File Acquire Path"; dlg.AutoProcess = false; dlg.EnableSizing = true; dlg.FileFormatsList = new RasterSaveDialogFileFormatsList(RasterDialogFileFormatDataContent.Default); dlg.ShowFileOptionsBasicJ2kOptions = false; dlg.ShowFileOptionsJ2kOptions = false; dlg.ShowFileOptionsMultipage = false; dlg.ShowFileOptionsProgressive = false; dlg.ShowFileOptionsQualityFactor = false; dlg.ShowFileOptionsStamp = false; dlg.ShowHelp = false; dlg.ShowOptions = false; dlg.ShowQualityFactor = false; if (dlg.ShowDialog(this) == DialogResult.OK) { // save the output file name _fileName = dlg.FileName; // save the output file format _fileFormat = dlg.Format; _bitsPerPixel = dlg.BitsPerPixel; string pathName = Path.GetDirectoryName(_fileName); if (Directory.Exists(pathName)) { // initialize the page counter _pageNo = 0; // Add the Acquire page event. _twainSession.AcquirePage += new EventHandler <TwainAcquirePageEventArgs>(_twain_AcquirePage); // Acquire pages _cleanupAfterAcquire = cleanup; if (_cleanupAfterAcquire) { ShowCleanUpMessage(); } _twainSession.Acquire(TwainUserInterfaceFlags.Show); // Remove the Acquire page event. _twainSession.AcquirePage -= new EventHandler <TwainAcquirePageEventArgs>(_twain_AcquirePage); } else { Messager.ShowError(this, "Invalid File Name"); } } } catch (Exception ex) { Messager.ShowError(this, ex); } finally { UpdateMyControls(); UpdateStatusBarText(); } }
public bool Save(IWin32Window owner, RasterCodecs codecs, List <string> tempFiles, bool viewOutputFile) { _format = RasterImageFormat.Unknown; _firstPage = -1; _lastPage = -1; _savePageNumber = -1; _pageMode = CodecsSavePageMode.Overwrite; RasterSaveDialog dlg = new RasterSaveDialog(codecs); dlg.PromptOverwrite = true; dlg.ShowFileOptionsBasicJ2kOptions = false; dlg.ShowFileOptionsJ2kOptions = false; dlg.ShowFileOptionsJbig2Options = false; #if LEADTOOLS_V16_OR_LATER dlg.ShowPdfProfiles = true; dlg.PdfProfile = PdfProfile; #endif // #if LEADTOOLS_V16_OR_LATER dlg.ShowFileOptionsMultipage = true; dlg.ShowFileOptionsProgressive = true; dlg.ShowFileOptionsQualityFactor = true; dlg.ShowFileOptionsStamp = true; dlg.ShowOptions = true; dlg.ShowQualityFactor = true; dlg.PageNumber = SavePageNumber; dlg.Title = "LEADTOOLS Save Dialog"; dlg.EnableSizing = true; dlg.FileName = FileName; dlg.FileSubTypeIndex = _fileSubTypeIndex; dlg.FileTypeIndex = _fileTypeIndex; dlg.BitsPerPixel = 0; if (null == SaveFormats) { dlg.FileFormatsList = new RasterSaveDialogFileFormatsList(RasterDialogFileFormatDataContent.Default); } else { dlg.FileFormatsList = SaveFormats; } if (dlg.ShowDialog(owner) == DialogResult.OK) { Application.DoEvents(); (owner as FrmMain).Cursor = Cursors.WaitCursor; FileName = dlg.FileName; _fileSubTypeIndex = dlg.FileSubTypeIndex; _fileTypeIndex = dlg.FileTypeIndex; _format = dlg.Format; _bitsPerPixel = dlg.BitsPerPixel; _firstPage = dlg.PageNumber; _lastPage = dlg.PageNumber; _savePageNumber = dlg.PageNumber; _pageMode = dlg.MultiPage; if (_autoSave) { switch (dlg.Format) { case RasterImageFormat.Abc: { codecs.Options.Abc.Save.QualityFactor = dlg.AbcQualityFactor; break; } #if !LEADTOOLS_V20_OR_LATER case RasterImageFormat.Ecw: { codecs.Options.Ecw.Save.QualityFactor = dlg.QualityFactor; break; } #endif // #if !LEADTOOLS_V20_OR_LATER case RasterImageFormat.Png: { codecs.Options.Png.Save.QualityFactor = dlg.QualityFactor; codecs.Options.Save.InitAlpha = true; break; } case RasterImageFormat.PngIco: { codecs.Options.Save.InitAlpha = true; break; } case RasterImageFormat.Cmp: { codecs.Options.Jpeg.Save.QualityFactor = dlg.QualityFactor; codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = dlg.CmpQualityFactor; break; } case RasterImageFormat.Xps: { codecs.Options.Save.InitAlpha = true; break; } default: { codecs.Options.Jpeg.Save.QualityFactor = dlg.QualityFactor; break; } } codecs.Options.Jpeg.Save.SaveWithStamp = dlg.WithStamp; codecs.Options.Jpeg.Save.StampWidth = dlg.StampWidth; codecs.Options.Jpeg.Save.StampHeight = dlg.StampHeight; codecs.Options.Jpeg.Save.StampBitsPerPixel = dlg.StampBitsPerPixel; if ((Format == RasterImageFormat.Cmw) || (Format == RasterImageFormat.J2k) || (Format == RasterImageFormat.Jp2) || (Format == RasterImageFormat.TifJ2k)) { #if !LEADTOOLS_V19_OR_LATER codecs.Options.Jpeg2000.Save.CodeBlockHeight = dlg.FileJ2kOptions.CodeBlockHeight; codecs.Options.Jpeg2000.Save.CodeBlockWidth = dlg.FileJ2kOptions.CodeBlockWidth; codecs.Options.Jpeg2000.Save.DerivedBaseExponent = dlg.FileJ2kOptions.DerivedBaseExponent; codecs.Options.Jpeg2000.Save.DerivedBaseMantissa = dlg.FileJ2kOptions.DerivedBaseMantissa; codecs.Options.Jpeg2000.Save.ErrorResilienceSymbol = dlg.FileJ2kOptions.ErrorResilienceSymbol; codecs.Options.Jpeg2000.Save.GuardBits = dlg.FileJ2kOptions.GuardBits; codecs.Options.Jpeg2000.Save.PredictableTermination = dlg.FileJ2kOptions.PredictableTermination; codecs.Options.Jpeg2000.Save.ResetContextOnBoundaries = dlg.FileJ2kOptions.ResetContextOnBoundaries; codecs.Options.Jpeg2000.Save.SelectiveAcBypass = dlg.FileJ2kOptions.SelectiveAcBypass; codecs.Options.Jpeg2000.Save.TerminationOnEachPass = dlg.FileJ2kOptions.TerminationOnEachPass; codecs.Options.Jpeg2000.Save.VerticallyCausalContext = dlg.FileJ2kOptions.VerticallyCausalContext; #endif // #if !LEADTOOLS_V19_OR_LATER codecs.Options.Jpeg2000.Save.CompressionControl = dlg.FileJ2kOptions.CompressionControl; codecs.Options.Jpeg2000.Save.CompressionRatio = dlg.FileJ2kOptions.CompressionRatio; codecs.Options.Jpeg2000.Save.DecompositionLevels = dlg.FileJ2kOptions.DecompositionLevels; codecs.Options.Jpeg2000.Save.DerivedQuantization = dlg.FileJ2kOptions.DerivedQuantization; codecs.Options.Jpeg2000.Save.ImageAreaHorizontalOffset = dlg.FileJ2kOptions.ImageAreaHorizontalOffset; codecs.Options.Jpeg2000.Save.ImageAreaVerticalOffset = dlg.FileJ2kOptions.ImageAreaVerticalOffset; codecs.Options.Jpeg2000.Save.ProgressingOrder = dlg.FileJ2kOptions.ProgressingOrder; codecs.Options.Jpeg2000.Save.ReferenceTileHeight = dlg.FileJ2kOptions.ReferenceTileHeight; codecs.Options.Jpeg2000.Save.ReferenceTileWidth = dlg.FileJ2kOptions.ReferenceTileWidth; codecs.Options.Jpeg2000.Save.RegionOfInterest = dlg.FileJ2kOptions.RegionOfInterest; codecs.Options.Jpeg2000.Save.RegionOfInterestRectangle = dlg.FileJ2kOptions.RegionOfInterestRectangle; codecs.Options.Jpeg2000.Save.RegionOfInterestWeight = dlg.FileJ2kOptions.RegionOfInterestWeight; codecs.Options.Jpeg2000.Save.TargetFileSize = dlg.FileJ2kOptions.TargetFileSize; codecs.Options.Jpeg2000.Save.TileHorizontalOffset = dlg.FileJ2kOptions.TileHorizontalOffset; codecs.Options.Jpeg2000.Save.TileVerticalOffset = dlg.FileJ2kOptions.TileVerticalOffset; codecs.Options.Jpeg2000.Save.UseColorTransform = dlg.FileJ2kOptions.UseColorTransform; codecs.Options.Jpeg2000.Save.UseEphMarker = dlg.FileJ2kOptions.UseEphMarker; codecs.Options.Jpeg2000.Save.UseRegionOfInterest = dlg.FileJ2kOptions.UseRegionOfInterest; codecs.Options.Jpeg2000.Save.UseSopMarker = dlg.FileJ2kOptions.UseSopMarker; } if ((Format == RasterImageFormat.TifJbig2) || (Format == RasterImageFormat.Jbig2)) { codecs.Options.Jbig2.Save.EnableDictionary = dlg.FileJbig2Options.EnableDictionary; codecs.Options.Jbig2.Save.ImageGbatX1 = dlg.FileJbig2Options.ImageGbatX1; codecs.Options.Jbig2.Save.ImageGbatX2 = dlg.FileJbig2Options.ImageGbatX2; codecs.Options.Jbig2.Save.ImageGbatX3 = dlg.FileJbig2Options.ImageGbatX3; codecs.Options.Jbig2.Save.ImageGbatX4 = dlg.FileJbig2Options.ImageGbatX4; codecs.Options.Jbig2.Save.ImageGbatY1 = dlg.FileJbig2Options.ImageGbatY1; codecs.Options.Jbig2.Save.ImageGbatY2 = dlg.FileJbig2Options.ImageGbatY2; codecs.Options.Jbig2.Save.ImageGbatY3 = dlg.FileJbig2Options.ImageGbatY3; codecs.Options.Jbig2.Save.ImageGbatY4 = dlg.FileJbig2Options.ImageGbatY4; codecs.Options.Jbig2.Save.ImageQualityFactor = dlg.FileJbig2Options.ImageQualityFactor; codecs.Options.Jbig2.Save.ImageTemplateType = dlg.FileJbig2Options.ImageTemplateType; codecs.Options.Jbig2.Save.ImageTypicalPredictionOn = dlg.FileJbig2Options.ImageTypicalPredictionOn; codecs.Options.Jbig2.Save.RemoveEofSegment = dlg.FileJbig2Options.RemoveEofSegment; codecs.Options.Jbig2.Save.RemoveEopSegment = dlg.FileJbig2Options.RemoveEopSegment; codecs.Options.Jbig2.Save.RemoveHeaderSegment = dlg.FileJbig2Options.RemoveHeaderSegment; codecs.Options.Jbig2.Save.RemoveMarker = dlg.FileJbig2Options.RemoveMarker; codecs.Options.Jbig2.Save.TextDifferentialThreshold = dlg.FileJbig2Options.TextDifferentialThreshold; codecs.Options.Jbig2.Save.TextGbatX1 = dlg.FileJbig2Options.TextGbatX1; codecs.Options.Jbig2.Save.TextGbatX2 = dlg.FileJbig2Options.TextGbatX2; codecs.Options.Jbig2.Save.TextGbatX3 = dlg.FileJbig2Options.TextGbatX3; codecs.Options.Jbig2.Save.TextGbatX4 = dlg.FileJbig2Options.TextGbatX4; codecs.Options.Jbig2.Save.TextGbatY1 = dlg.FileJbig2Options.TextGbatY1; codecs.Options.Jbig2.Save.TextGbatY2 = dlg.FileJbig2Options.TextGbatY2; codecs.Options.Jbig2.Save.TextGbatY3 = dlg.FileJbig2Options.TextGbatY3; codecs.Options.Jbig2.Save.TextGbatY4 = dlg.FileJbig2Options.TextGbatY4; codecs.Options.Jbig2.Save.TextKeepAllSymbols = dlg.FileJbig2Options.TextKeepAllSymbols; codecs.Options.Jbig2.Save.TextMaximumSymbolArea = dlg.FileJbig2Options.TextMaximumSymbolArea; codecs.Options.Jbig2.Save.TextMaximumSymbolHeight = dlg.FileJbig2Options.TextMaximumSymbolHeight; codecs.Options.Jbig2.Save.TextMaximumSymbolWidth = dlg.FileJbig2Options.TextMaximumSymbolWidth; codecs.Options.Jbig2.Save.TextMinimumSymbolArea = dlg.FileJbig2Options.TextMinimumSymbolArea; codecs.Options.Jbig2.Save.TextMinimumSymbolHeight = dlg.FileJbig2Options.TextMinimumSymbolHeight; codecs.Options.Jbig2.Save.TextMinimumSymbolWidth = dlg.FileJbig2Options.TextMinimumSymbolWidth; codecs.Options.Jbig2.Save.TextQualityFactor = dlg.FileJbig2Options.TextQualityFactor; codecs.Options.Jbig2.Save.TextRemoveUnrepeatedSymbol = dlg.FileJbig2Options.TextRemoveUnrepeatedSymbol; codecs.Options.Jbig2.Save.TextTemplateType = dlg.FileJbig2Options.TextTemplateType; codecs.Options.Jbig2.Save.XResolution = dlg.FileJbig2Options.XResolution; codecs.Options.Jbig2.Save.YResolution = dlg.FileJbig2Options.YResolution; } if (Format == RasterImageFormat.Gif) { codecs.Options.Gif.Save.Interlaced = dlg.Interlaced; } #if LEADTOOLS_V16_OR_LATER PdfProfile = dlg.PdfProfile; if ((Format == RasterImageFormat.RasPdf) || (Format == RasterImageFormat.RasPdfG31Dim) || (Format == RasterImageFormat.RasPdfG32Dim) || (Format == RasterImageFormat.RasPdfG4) || (Format == RasterImageFormat.RasPdfJbig2) || (Format == RasterImageFormat.RasPdfJpeg) || (Format == RasterImageFormat.RasPdfJpeg422) || (Format == RasterImageFormat.RasPdfJpeg411)) { codecs.Options.Pdf.Save.SavePdfA = false; codecs.Options.Pdf.Save.SavePdfv13 = false; codecs.Options.Pdf.Save.SavePdfv14 = false; codecs.Options.Pdf.Save.SavePdfv15 = false; codecs.Options.Pdf.Save.SavePdfv16 = false; switch (PdfProfile) { case FileSavePdfProfiles.PdfA: codecs.Options.Pdf.Save.SavePdfA = true; break; case FileSavePdfProfiles.Pdf13: codecs.Options.Pdf.Save.SavePdfv13 = true; break; case FileSavePdfProfiles.Pdf14: codecs.Options.Pdf.Save.SavePdfv14 = true; break; case FileSavePdfProfiles.Pdf15: codecs.Options.Pdf.Save.SavePdfv15 = true; break; case FileSavePdfProfiles.Pdf16: codecs.Options.Pdf.Save.SavePdfv16 = true; break; } } #endif RasterImage image = codecs.Load(tempFiles[0]); for (int i = 1; i < tempFiles.Count; i++) { image.AddPage(codecs.Load(tempFiles[i])); } if (_format == RasterImageFormat.Ani || _format == RasterImageFormat.Gif || _format == RasterImageFormat.Cals || _format == RasterImageFormat.Cals2 || _format == RasterImageFormat.Cals3 || _format == RasterImageFormat.Cals4 || _format == RasterImageFormat.Pcx || _format == RasterImageFormat.Fpx || _format == RasterImageFormat.FpxJpeg || _format == RasterImageFormat.FpxJpegQFactor || _format == RasterImageFormat.FpxSingleColor || _format == RasterImageFormat.Flc || _format == RasterImageFormat.IffCat || _format == RasterImageFormat.IcaAbic || _format == RasterImageFormat.IcaG31Dim || _format == RasterImageFormat.IcaG32Dim || _format == RasterImageFormat.IcaG4 || _format == RasterImageFormat.IcaIbmMmr || _format == RasterImageFormat.IcaUncompressed || _format == RasterImageFormat.AfpIcaG31Dim || _format == RasterImageFormat.AfpIcaG32Dim || _format == RasterImageFormat.AfpIcaG4 || _format == RasterImageFormat.AfpIcaIbmMmr || _format == RasterImageFormat.AfpIcaUncompressed || _format == RasterImageFormat.Mng || _format == RasterImageFormat.MngGray || _format == RasterImageFormat.MngJng || _format == RasterImageFormat.MngJng411 || _format == RasterImageFormat.MngJng422 || _format == RasterImageFormat.Pct || _format == RasterImageFormat.Pcx || _format == RasterImageFormat.RasPdf || _format == RasterImageFormat.RasPdfCmyk || _format == RasterImageFormat.RasPdfG31Dim || _format == RasterImageFormat.RasPdfG32Dim || _format == RasterImageFormat.RasPdfG4 || _format == RasterImageFormat.RasPdfJbig2 || _format == RasterImageFormat.RasPdfJpeg || _format == RasterImageFormat.RasPdfJpeg411 || _format == RasterImageFormat.RasPdfJpeg422 || _format == RasterImageFormat.RasPdfLzw || _format == RasterImageFormat.RasPdfLzwCmyk || _format == RasterImageFormat.Sff || _format == RasterImageFormat.Ccitt || _format == RasterImageFormat.CcittGroup31Dim || _format == RasterImageFormat.CcittGroup32Dim || _format == RasterImageFormat.CcittGroup4 || _format == RasterImageFormat.GeoTiff || _format == RasterImageFormat.Exif || _format == RasterImageFormat.ExifJpeg || _format == RasterImageFormat.ExifJpeg411 || _format == RasterImageFormat.ExifJpeg422 || _format == RasterImageFormat.ExifYcc || _format == RasterImageFormat.Tif || _format == RasterImageFormat.TifAbc || _format == RasterImageFormat.TifAbic || _format == RasterImageFormat.TifCmp || _format == RasterImageFormat.TifCmw || _format == RasterImageFormat.TifCmyk || _format == RasterImageFormat.TifCustom || _format == RasterImageFormat.TifDxf || _format == RasterImageFormat.TifJ2k || _format == RasterImageFormat.TifJbig || _format == RasterImageFormat.TifJbig2 || _format == RasterImageFormat.TifJpeg || _format == RasterImageFormat.TifJpeg411 || _format == RasterImageFormat.TifJpeg422 || _format == RasterImageFormat.TifLead1Bit || _format == RasterImageFormat.TifLzw || _format == RasterImageFormat.TifLzwCmyk || _format == RasterImageFormat.TifLzwYcc || _format == RasterImageFormat.TifPackBits || _format == RasterImageFormat.TifPackBitsCmyk || _format == RasterImageFormat.TifPackbitsYcc || _format == RasterImageFormat.TifUnknown || _format == RasterImageFormat.TifxFaxG31D || _format == RasterImageFormat.TifxFaxG32D || _format == RasterImageFormat.TifxFaxG4 || _format == RasterImageFormat.TifxJbig || _format == RasterImageFormat.TifxJbigT43 || _format == RasterImageFormat.TifxJbigT43Gs || _format == RasterImageFormat.TifxJbigT43ItuLab || _format == RasterImageFormat.TifxJpeg || _format == RasterImageFormat.TifYcc || _format == RasterImageFormat.TifZip) { codecs.Save(image, _fileName, _format, _bitsPerPixel, image.Page, image.PageCount, _savePageNumber, _pageMode); if (viewOutputFile) { System.Diagnostics.Process.Start(_fileName); } } else { for (int i = 0; i < image.PageCount; i++) { string ext = System.IO.Path.GetExtension(_fileName); int index = _fileName.IndexOf(ext); string newFileName = _fileName.Insert(index, "_" + (i + 1).ToString()); image.Page = i + 1; codecs.Save(image, newFileName, _format, _bitsPerPixel, i + 1, i + 1, 0, CodecsSavePageMode.Overwrite); } string ext2 = System.IO.Path.GetExtension(_fileName); int index2 = _fileName.IndexOf(ext2); string openFileName = _fileName.Insert(index2, "_" + 1.ToString()); if (viewOutputFile) { System.Diagnostics.Process.Start(openFileName); } } if (image != null) { image.Dispose(); } } return(true); } else { return(false); } }
/// <summary> /// Load a new image /// </summary> private void _miFileOpen_Click(object sender, System.EventArgs e) { RasterCodecs _codecs = null; CodecsImageInfo imageInfo = null; try { // initialize the codecs object. _codecs = new RasterCodecs(); // Since we are dealing with large images, we do not want to allocate the entire image. We are only going to load it row by row _codecs.Options.Load.AllocateImage = false; _codecs.Options.Load.StoreDataInImage = false; _codecs.LoadImage += new EventHandler <CodecsLoadImageEventArgs>(codecs_LoadImage); // load the image OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Open File"; openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Check if image is valid for this demo imageInfo = _codecs.GetInformation(openFileDialog.FileName, false); if (!IsImageValid(imageInfo)) { Messager.ShowError(this, "The input image has to be 8-bit Gray scale, 12-bit Gray scale, 16-bit Gray scale, RGB (color), and TopLeft view perspective." + " This DEMO is not meant to be used with small or palletized images (like GIF, PNG, or 1-bit images)." + " Use this DEMO to save large dimension images efficiently using JPEG2000 compression."); return; } using (RasterSaveDialog saveDialog = new RasterSaveDialog(_codecs)) { saveDialog.AutoProcess = false; saveDialog.Title = "Save As"; saveDialog.ShowFileOptionsBasicJ2kOptions = true; saveDialog.ShowFileOptionsJ2kOptions = true; saveDialog.ShowOptions = true; saveDialog.ShowQualityFactor = true; saveDialog.ShowFileOptionsProgressive = true; saveDialog.ShowFileOptionsStamp = true; saveDialog.QualityFactor = 20; SetupFormats(saveDialog); if (saveDialog.ShowDialog(this) != DialogResult.OK) { return; } _lblFilenameValue.Text = Path.GetFileName(openFileDialog.FileName); _lblDimensionValue.Text = String.Format("{0} x {1}", imageInfo.Width, imageInfo.Height); _lblImageBitsPerPixelValue.Text = imageInfo.BitsPerPixel.ToString(); //Get the selected compression type CodecsCompression selectedCompression; if (saveDialog.Format == RasterImageFormat.J2k) { selectedCompression = CodecsCompression.J2k; } else { selectedCompression = CodecsCompression.Jp2; } RasterByteOrder rasterByteOrder = ((saveDialog.BitsPerPixel == 12) || (saveDialog.BitsPerPixel == 16)) ? RasterByteOrder.Gray : RasterByteOrder.Bgr; CodecsLoadByteOrder codecsLoadByteOrder = ((saveDialog.BitsPerPixel == 12) || (saveDialog.BitsPerPixel == 16)) ? CodecsLoadByteOrder.Gray : CodecsLoadByteOrder.Bgr; bytesPerLine = CalculateBytesPerLine(saveDialog.BitsPerPixel, imageInfo.Width); _codecs.Options.Jpeg.Save.QualityFactor = saveDialog.QualityFactor; _codecs.Options.Jpeg.Save.Passes = saveDialog.Passes; _codecs.Options.Jpeg.Save.SaveWithStamp = saveDialog.WithStamp; _codecs.Options.Jpeg.Save.StampWidth = saveDialog.StampWidth; _codecs.Options.Jpeg.Save.StampHeight = saveDialog.StampHeight; _codecs.Options.Jpeg.Save.StampBitsPerPixel = saveDialog.StampBitsPerPixel; _codecs.Options.Jpeg2000.Save.CompressionControl = saveDialog.FileJ2kOptions.CompressionControl; _codecs.Options.Jpeg2000.Save.CompressionRatio = saveDialog.FileJ2kOptions.CompressionRatio; _codecs.Options.Jpeg2000.Save.DecompositionLevels = saveDialog.FileJ2kOptions.DecompositionLevels; _codecs.Options.Jpeg2000.Save.DerivedQuantization = saveDialog.FileJ2kOptions.DerivedQuantization; _codecs.Options.Jpeg2000.Save.ImageAreaHorizontalOffset = saveDialog.FileJ2kOptions.ImageAreaHorizontalOffset; _codecs.Options.Jpeg2000.Save.ImageAreaVerticalOffset = saveDialog.FileJ2kOptions.ImageAreaVerticalOffset; _codecs.Options.Jpeg2000.Save.ProgressingOrder = saveDialog.FileJ2kOptions.ProgressingOrder; _codecs.Options.Jpeg2000.Save.ReferenceTileHeight = saveDialog.FileJ2kOptions.ReferenceTileHeight; _codecs.Options.Jpeg2000.Save.ReferenceTileWidth = saveDialog.FileJ2kOptions.ReferenceTileWidth; _codecs.Options.Jpeg2000.Save.RegionOfInterest = saveDialog.FileJ2kOptions.RegionOfInterest; _codecs.Options.Jpeg2000.Save.RegionOfInterestRectangle = saveDialog.FileJ2kOptions.RegionOfInterestRectangle; _codecs.Options.Jpeg2000.Save.RegionOfInterestWeight = saveDialog.FileJ2kOptions.RegionOfInterestWeight; _codecs.Options.Jpeg2000.Save.TargetFileSize = saveDialog.FileJ2kOptions.TargetFileSize; _codecs.Options.Jpeg2000.Save.TileHorizontalOffset = saveDialog.FileJ2kOptions.TileHorizontalOffset; _codecs.Options.Jpeg2000.Save.TileVerticalOffset = saveDialog.FileJ2kOptions.TileVerticalOffset; _codecs.Options.Jpeg2000.Save.UseColorTransform = saveDialog.FileJ2kOptions.UseColorTransform; _codecs.Options.Jpeg2000.Save.UseEphMarker = saveDialog.FileJ2kOptions.UseEphMarker; _codecs.Options.Jpeg2000.Save.UseRegionOfInterest = saveDialog.FileJ2kOptions.UseRegionOfInterest; _codecs.Options.Jpeg2000.Save.UseSopMarker = saveDialog.FileJ2kOptions.UseSopMarker; bCancel = false; bCompressing = true; UpdateMyControls(); //Start Compressing using (outputFile = File.Create(saveDialog.FileName)) { _codecs.StartCompress(imageInfo.Width, imageInfo.Height, saveDialog.BitsPerPixel, rasterByteOrder, RasterViewPerspective.TopLeft, bytesPerLine, IntPtr.Zero, 0, selectedCompression, MyCodecsCompressDataCallback); _codecs.Load(openFileDialog.FileName, saveDialog.BitsPerPixel, codecsLoadByteOrder, 1, 1); _codecs.StopCompress(); _lblStatusValue.Text = bCancel ? "Aborted" : "Complete"; } } } } catch (Exception ex) { Messager.ShowError(this, ex); _lblStatusValue.Text = "Error"; } finally { if (_codecs != null) { _codecs.Dispose(); } if (imageInfo != null) { imageInfo.Dispose(); } bCompressing = false; UpdateMyControls(); } }
public bool Save(IWin32Window owner, RasterCodecs codecs, RasterImage image) { _format = RasterImageFormat.Unknown; _firstPage = -1; _lastPage = -1; _savePageNumber = -1; _pageMode = CodecsSavePageMode.Overwrite; using (RasterSaveDialog dlg = new RasterSaveDialog(codecs)) { dlg.PromptOverwrite = true; dlg.ShowFileOptionsBasicJ2kOptions = true; dlg.ShowFileOptionsJ2kOptions = true; dlg.ShowFileOptionsJbig2Options = true; dlg.ShowPdfProfiles = true; dlg.PdfProfile = PdfProfile; dlg.ShowFileOptionsMultipage = true; dlg.ShowFileOptionsProgressive = true; dlg.Passes = _passes; dlg.ShowFileOptionsQualityFactor = true; dlg.ShowFileOptionsStamp = true; dlg.ShowOptions = true; dlg.ShowQualityFactor = true; dlg.PageNumber = SavePageNumber; dlg.Title = "LEADTOOLS Save Dialog"; dlg.EnableSizing = true; dlg.FileName = FileName; dlg.FileSubTypeIndex = _fileSubTypeIndex; dlg.FileTypeIndex = _fileTypeIndex; if (image != null) { dlg.BitsPerPixel = image.BitsPerPixel; } else { dlg.BitsPerPixel = 0; } if (null == SaveFormats) { dlg.FileFormatsList = new RasterSaveDialogFileFormatsList(RasterDialogFileFormatDataContent.Default); } else { dlg.FileFormatsList = SaveFormats; } if (dlg.ShowDialog(owner) == DialogResult.OK) { FileName = dlg.FileName; _fileSubTypeIndex = dlg.FileSubTypeIndex; _fileTypeIndex = dlg.FileTypeIndex; _format = dlg.Format; _bitsPerPixel = dlg.BitsPerPixel; _firstPage = dlg.PageNumber; _lastPage = dlg.PageNumber; _savePageNumber = dlg.PageNumber; _pageMode = dlg.MultiPage; _passes = dlg.Passes; if (_autoSave) { switch (dlg.Format) { case RasterImageFormat.Abc: { codecs.Options.Abc.Save.QualityFactor = dlg.AbcQualityFactor; break; } #if !LEADTOOLS_V20_OR_LATER case RasterImageFormat.Ecw: { codecs.Options.Ecw.Save.QualityFactor = dlg.QualityFactor; break; } #endif // #if !LEADTOOLS_V20_OR_LATER case RasterImageFormat.Png: { codecs.Options.Png.Save.QualityFactor = dlg.QualityFactor; codecs.Options.Save.InitAlpha = true; break; } case RasterImageFormat.PngIco: { codecs.Options.Save.InitAlpha = true; break; } case RasterImageFormat.Cmp: { codecs.Options.Jpeg.Save.QualityFactor = dlg.QualityFactor; codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = dlg.CmpQualityFactor; codecs.Options.Jpeg.Save.Passes = dlg.Passes; break; } case RasterImageFormat.Xps: { codecs.Options.Save.InitAlpha = true; break; } default: { codecs.Options.Jpeg.Save.QualityFactor = dlg.QualityFactor; codecs.Options.Jpeg.Save.Passes = dlg.Passes; break; } } codecs.Options.Jpeg.Save.SaveWithStamp = dlg.WithStamp; codecs.Options.Jpeg.Save.StampWidth = dlg.StampWidth; codecs.Options.Jpeg.Save.StampHeight = dlg.StampHeight; codecs.Options.Jpeg.Save.StampBitsPerPixel = dlg.StampBitsPerPixel; if ((Format == RasterImageFormat.Cmw) || (Format == RasterImageFormat.J2k) || (Format == RasterImageFormat.Jp2) || (Format == RasterImageFormat.TifJ2k) || (Format == RasterImageFormat.Jpx) || (Format == RasterImageFormat.RasPdfJpx) || (Format == RasterImageFormat.DicomJpxGray) || (Format == RasterImageFormat.DicomJpxColor)) { codecs.Options.Jpeg2000.Save.CompressionControl = dlg.FileJ2kOptions.CompressionControl; if (codecs.Options.Jpeg2000.Save.CompressionControl == CodecsJpeg2000CompressionControl.Lossless) { codecs.Options.Jpeg.Save.QualityFactor = 0; } codecs.Options.Jpeg2000.Save.CompressionRatio = dlg.FileJ2kOptions.CompressionRatio; codecs.Options.Jpeg2000.Save.DecompositionLevels = dlg.FileJ2kOptions.DecompositionLevels; codecs.Options.Jpeg2000.Save.DerivedQuantization = dlg.FileJ2kOptions.DerivedQuantization; codecs.Options.Jpeg2000.Save.ImageAreaHorizontalOffset = dlg.FileJ2kOptions.ImageAreaHorizontalOffset; codecs.Options.Jpeg2000.Save.ImageAreaVerticalOffset = dlg.FileJ2kOptions.ImageAreaVerticalOffset; codecs.Options.Jpeg2000.Save.ProgressingOrder = dlg.FileJ2kOptions.ProgressingOrder; codecs.Options.Jpeg2000.Save.ReferenceTileHeight = dlg.FileJ2kOptions.ReferenceTileHeight; codecs.Options.Jpeg2000.Save.ReferenceTileWidth = dlg.FileJ2kOptions.ReferenceTileWidth; codecs.Options.Jpeg2000.Save.RegionOfInterest = dlg.FileJ2kOptions.RegionOfInterest; codecs.Options.Jpeg2000.Save.RegionOfInterestRectangle = dlg.FileJ2kOptions.RegionOfInterestRectangle; codecs.Options.Jpeg2000.Save.RegionOfInterestWeight = dlg.FileJ2kOptions.RegionOfInterestWeight; codecs.Options.Jpeg2000.Save.TargetFileSize = dlg.FileJ2kOptions.TargetFileSize; codecs.Options.Jpeg2000.Save.TileHorizontalOffset = dlg.FileJ2kOptions.TileHorizontalOffset; codecs.Options.Jpeg2000.Save.TileVerticalOffset = dlg.FileJ2kOptions.TileVerticalOffset; codecs.Options.Jpeg2000.Save.UseColorTransform = dlg.FileJ2kOptions.UseColorTransform; codecs.Options.Jpeg2000.Save.UseEphMarker = dlg.FileJ2kOptions.UseEphMarker; codecs.Options.Jpeg2000.Save.UseRegionOfInterest = dlg.FileJ2kOptions.UseRegionOfInterest; codecs.Options.Jpeg2000.Save.UseSopMarker = dlg.FileJ2kOptions.UseSopMarker; } if ((Format == RasterImageFormat.TifJbig2) || (Format == RasterImageFormat.Jbig2)) { codecs.Options.Jbig2.Save.EnableDictionary = dlg.FileJbig2Options.EnableDictionary; codecs.Options.Jbig2.Save.ImageGbatX1 = dlg.FileJbig2Options.ImageGbatX1; codecs.Options.Jbig2.Save.ImageGbatX2 = dlg.FileJbig2Options.ImageGbatX2; codecs.Options.Jbig2.Save.ImageGbatX3 = dlg.FileJbig2Options.ImageGbatX3; codecs.Options.Jbig2.Save.ImageGbatX4 = dlg.FileJbig2Options.ImageGbatX4; codecs.Options.Jbig2.Save.ImageGbatY1 = dlg.FileJbig2Options.ImageGbatY1; codecs.Options.Jbig2.Save.ImageGbatY2 = dlg.FileJbig2Options.ImageGbatY2; codecs.Options.Jbig2.Save.ImageGbatY3 = dlg.FileJbig2Options.ImageGbatY3; codecs.Options.Jbig2.Save.ImageGbatY4 = dlg.FileJbig2Options.ImageGbatY4; codecs.Options.Jbig2.Save.ImageQualityFactor = dlg.FileJbig2Options.ImageQualityFactor; codecs.Options.Jbig2.Save.ImageTemplateType = dlg.FileJbig2Options.ImageTemplateType; codecs.Options.Jbig2.Save.ImageTypicalPredictionOn = dlg.FileJbig2Options.ImageTypicalPredictionOn; codecs.Options.Jbig2.Save.RemoveEofSegment = dlg.FileJbig2Options.RemoveEofSegment; codecs.Options.Jbig2.Save.RemoveEopSegment = dlg.FileJbig2Options.RemoveEopSegment; codecs.Options.Jbig2.Save.RemoveHeaderSegment = dlg.FileJbig2Options.RemoveHeaderSegment; codecs.Options.Jbig2.Save.RemoveMarker = dlg.FileJbig2Options.RemoveMarker; codecs.Options.Jbig2.Save.TextDifferentialThreshold = dlg.FileJbig2Options.TextDifferentialThreshold; codecs.Options.Jbig2.Save.TextGbatX1 = dlg.FileJbig2Options.TextGbatX1; codecs.Options.Jbig2.Save.TextGbatX2 = dlg.FileJbig2Options.TextGbatX2; codecs.Options.Jbig2.Save.TextGbatX3 = dlg.FileJbig2Options.TextGbatX3; codecs.Options.Jbig2.Save.TextGbatX4 = dlg.FileJbig2Options.TextGbatX4; codecs.Options.Jbig2.Save.TextGbatY1 = dlg.FileJbig2Options.TextGbatY1; codecs.Options.Jbig2.Save.TextGbatY2 = dlg.FileJbig2Options.TextGbatY2; codecs.Options.Jbig2.Save.TextGbatY3 = dlg.FileJbig2Options.TextGbatY3; codecs.Options.Jbig2.Save.TextGbatY4 = dlg.FileJbig2Options.TextGbatY4; codecs.Options.Jbig2.Save.TextKeepAllSymbols = dlg.FileJbig2Options.TextKeepAllSymbols; codecs.Options.Jbig2.Save.TextMaximumSymbolArea = dlg.FileJbig2Options.TextMaximumSymbolArea; codecs.Options.Jbig2.Save.TextMaximumSymbolHeight = dlg.FileJbig2Options.TextMaximumSymbolHeight; codecs.Options.Jbig2.Save.TextMaximumSymbolWidth = dlg.FileJbig2Options.TextMaximumSymbolWidth; codecs.Options.Jbig2.Save.TextMinimumSymbolArea = dlg.FileJbig2Options.TextMinimumSymbolArea; codecs.Options.Jbig2.Save.TextMinimumSymbolHeight = dlg.FileJbig2Options.TextMinimumSymbolHeight; codecs.Options.Jbig2.Save.TextMinimumSymbolWidth = dlg.FileJbig2Options.TextMinimumSymbolWidth; codecs.Options.Jbig2.Save.TextQualityFactor = dlg.FileJbig2Options.TextQualityFactor; codecs.Options.Jbig2.Save.TextRemoveUnrepeatedSymbol = dlg.FileJbig2Options.TextRemoveUnrepeatedSymbol; codecs.Options.Jbig2.Save.TextTemplateType = dlg.FileJbig2Options.TextTemplateType; codecs.Options.Jbig2.Save.XResolution = dlg.FileJbig2Options.XResolution; codecs.Options.Jbig2.Save.YResolution = dlg.FileJbig2Options.YResolution; } if (Format == RasterImageFormat.Jbig2) { codecs.Options.Jbig2.Save.ImageQualityFactor = dlg.QualityFactor; } if (Format == RasterImageFormat.Gif) { codecs.Options.Gif.Save.Interlaced = dlg.Interlaced; } PdfProfile = dlg.PdfProfile; if ((Format == RasterImageFormat.RasPdf) || (Format == RasterImageFormat.RasPdfG31Dim) || (Format == RasterImageFormat.RasPdfG32Dim) || (Format == RasterImageFormat.RasPdfG4) || (Format == RasterImageFormat.RasPdfJbig2) || (Format == RasterImageFormat.RasPdfJpeg) || (Format == RasterImageFormat.RasPdfJpeg422) || (Format == RasterImageFormat.RasPdfJpeg411) || (Format == RasterImageFormat.RasPdfJpx)) { switch (PdfProfile) { case FileSavePdfProfiles.PdfA: codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.PdfA; break; case FileSavePdfProfiles.Pdf14: codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V14; break; case FileSavePdfProfiles.Pdf15: codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V15; break; case FileSavePdfProfiles.Pdf16: codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V16; break; case FileSavePdfProfiles.Pdf13: codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V13; break; #if LEADTOOLS_V175_OR_LATER case FileSavePdfProfiles.Pdf17: codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V17; break; #endif case FileSavePdfProfiles.Default: default: codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V12; break; } } #if LEADTOOLS_V19_OR_LATER if (dlg.BigTiff) { codecs.Options.Tiff.Save.BigTiff = true; } else { codecs.Options.Tiff.Save.BigTiff = false; } #endif codecs.Save(image, _fileName, _format, _bitsPerPixel, image.Page, image.PageCount, _savePageNumber, _pageMode); } return(true); } else { return(false); } } }