public static MemoryStream ToStream(this RasterImage image, RasterImageFormat format, int compression) { MemoryStream fileStream = new MemoryStream(); _Codecs.Options.Jpeg.Save.QualityFactor = compression; _Codecs.Save(image, fileStream, format, 0); return(fileStream); }
private void _btnOK_Click(object sender, System.EventArgs e) { RasterImageFormat format = RasterImageFormat.Tif; string baseFileName = ""; bool multiPage = true; int bpp = 1; switch (_transferMode) { case TwainTransferMode.File: format = _format[_cmbFileFormats.SelectedIndex]; if (!_cmbFileFormats.Text.Equals("TIFF MULTI")) { multiPage = false; } break; case TwainTransferMode.Buffer: if (_cbUseBufferSize.Checked && _txtBufferSize.Text == "0") { Messager.ShowError(this, "Please, enter valid custom buffer size"); return; } format = _format[_cmbFileFormats.SelectedIndex]; bpp = _memoryFormatBPP[_cmbFileFormats.SelectedIndex]; multiPage = _memoryFormatMulti[_cmbFileFormats.SelectedIndex]; break; case TwainTransferMode.Native: format = _imageLEADFormat; bpp = _nativeBPP; break; } Hide(); try { _session.EnableAcquireMultiPageEvent = false; baseFileName = _txtFileName.Text; _session.AcquireFast(baseFileName, TwainFastUserInterfaceFlags.Show | TwainFastUserInterfaceFlags.Modal, _transferMode, format, bpp, multiPage, _bufferSize, !_cbUseBufferSize.Checked); Messager.ShowInformation(this, "Process Completed"); } catch (Exception ex) { Messager.ShowError(this, ex); } DialogResult = DialogResult.OK; }
public ExportImageFormat(string displayName, RasterImageFormat format, bool canCompress, bool canReduceBitdepth, bool canPreserveBitdepth) { DisplayName = displayName; Format = format; CanCompress = canCompress; CanReduceBitdepth = canReduceBitdepth; CanPreserveBitdepth = canPreserveBitdepth; }
/// <summary> /// アプリケーションの初期化処理を行います。 /// </summary> private void InitClass() { // フォームのタイトルを設定します。 this.Text = "TWAIN 取得 【振替伝票読み取り】"; //自分自身のバージョン情報を取得する 2011/03/25 //System.Diagnostics.FileVersionInfo ver = // System.Diagnostics.FileVersionInfo.GetVersionInfo( // System.Reflection.Assembly.GetExecutingAssembly().Location); //キャプションにバージョンを追加 2011/03/25 //Messager.Caption += " ver " + ver.FileMajorPart.ToString() + "." + ver.FileMinorPart.ToString(); //Text = Messager.Caption; // ロック解除状態を確認します。 //Support.Unlock(false); // RasterImageViewerコントロールを初期化します。 _viewer = new RasterImageViewer(); //_viewer.Dock = DockStyle.Fill; _viewer.BackColor = Color.DarkGray; Controls.Add(_viewer); _viewer.BringToFront(); _viewer.Visible = false; // コーデックパスを設定します。 RasterCodecs.Startup(); // RasterCodecsオブジェクトを初期化します。 _codecs = new RasterCodecs(); if (TwainSession.IsAvailable(this)) { // TwainSessionオブジェクトを初期化します。 _twainSession = new TwainSession(); // TWAIN セッションを初期化します。 _twainSession.Startup(this, "FKDL", "LEADTOOLS", "Ver16.5J", "OCR", TwainStartupFlags.None); //_twainSession.Startup2(this, "FKDL", "LEADTOOLS", "Ver16.5J", "OCR", TwainStartupFlags.None, TwainLanguage.LanguageJapanese, TwainCountry.CountryJapan); } else { //_miFileAcquire.Enabled = false; //_miFileSelectSource.Enabled = false; } // 各値を初期化します。 _fileName = string.Empty; _fileFormat = RasterImageFormat.Tif; _pageNo = 1; _sFileNumber = 0; //UpdateMyControls(); UpdateStatusBarText(); }
/// <summary> /// スキャナより勤務票をスキャンして画像を取得します /// </summary> private void ScanOcr() { //出力先パス初期化 _ocrPath = string.Empty; try { RasterSaveDialogFileFormatsList saveDlgFormatList = new RasterSaveDialogFileFormatsList(RasterDialogFileFormatDataContent.User); string tifPath = Properties.Settings.Default.PathInst + Properties.Settings.Default.PathSCAN; _fileName = tifPath + string.Format("{0:0000}", DateTime.Today.Year) + string.Format("{0:00}", DateTime.Today.Month) + string.Format("{0:00}", DateTime.Today.Day) + string.Format("{0:00}", DateTime.Now.Hour) + string.Format("{0:00}", DateTime.Now.Minute) + string.Format("{0:00}", DateTime.Now.Second) + ".tif"; ///以下、TWAIN取得関連 ////////////////////////////////////////////////////////////////////// _fileFormat = RasterImageFormat.CcittGroup4; _bitsPerPixel = 1; string pathName = System.IO.Path.GetDirectoryName(_fileName); if (System.IO.Directory.Exists(pathName)) { // ページカウンタを初期化します。 _pageNo = 1; // 出力ファイルカウンタをインクリメントします。 _sFileNumber++; // AcquirePageイベントハンドラを設定します。 _twainSession.AcquirePage += new EventHandler <TwainAcquirePageEventArgs>(_twain_AcquirePage); // Acquire pages _twainSession.Acquire(TwainUserInterfaceFlags.Show); // AcquirePageイベントハンドラを削除します。 _twainSession.AcquirePage -= new EventHandler <TwainAcquirePageEventArgs>(_twain_AcquirePage); } else { MessageBox.Show("ファイル名の書式が正しくありません。"); } } catch (Exception ex) { MessageBox.Show(ex.Message); _twainSession.Shutdown(); _twainSession.Startup(this, "GrapeCity Inc.", "LEADTOOLS", "Ver.16.5J", "LEADTOOLS TWAIN 取得 サンプル", TwainStartupFlags.None); } finally { UpdateStatusBarText(); } }
public static int GetFormatIndex(RasterImageFormat format) { for (int i = 0; i < RasterFormats.Length; i++) { if (RasterFormats[i] == format) { return(i); } } return(-1); }
string GetExtension(RasterImageFormat imageFormat) { switch (imageFormat) { case RasterImageFormat.Jpeg: return(".jpg"); case RasterImageFormat.RasPdfJpeg: return(".pdf"); } //default return(".jpg"); }
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; }
/// <param name="yfile">源图像</param> /// <param name="mfile">新图像</param> /// <param name="p1">页码1</param> /// <param name="p2">页码2</param> /// <param name="fileformat">图像格式</param> public static bool _SplitImg(string yfile, string mfile, int p1, int p2, string fileformat) { try { RasterImageFormat format = new RasterImageFormat(); if (fileformat.IndexOf("jpg") >= 0) { format = RasterImageFormat.Jpeg; } else if (fileformat.IndexOf("pdf") >= 0) { format = RasterImageFormat.RasPdfJpeg; } else if (fileformat.IndexOf("tif") >= 0) { format = RasterImageFormat.TifJpeg; } RasterImage _imagepx; RasterCodecs _Codef = new RasterCodecs(); for (int i = p1; i <= p2; i++) { _imagepx = _Codef.Load(yfile, 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, i, i); int bit = _imagepx.BitsPerPixel; if (bit != 1) { if (bit != 8) { // _Codef.Options.Jpeg.Save.QualityFactor = 80; _Codef.Save(_imagepx, mfile, format, bit, 1, 1, i, CodecsSavePageMode.Append); } else { // _Codef.Options.Jpeg.Save.QualityFactor = Factor; _Codef.Save(_imagepx, mfile, format, 8, 1, 1, i, CodecsSavePageMode.Append); } } else { _Codef.Save(_imagepx, mfile, format, 1, 1, 1, -1, CodecsSavePageMode.Append); } } _Codef.Dispose(); return(true); } catch { return(false); } }
RasterCodecs GetRasterCodecs(RasterImageFormat imageFormat) { RasterCodecs codecs = new RasterCodecs(); switch (imageFormat) { case RasterImageFormat.Jpeg: codecs.Options.Jpeg.Save.QualityFactor = 2; break; case RasterImageFormat.RasPdfJpeg: codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V12; break; } return(codecs); }
private string GetFormatFilter() { int selectedFormatIndex = _cmbFileFormats.SelectedIndex; RasterImageFormat myFormat = _format[selectedFormatIndex]; string formatFilter = "All files (*.*)|*.*";; switch (myFormat) { case RasterImageFormat.Tif: case RasterImageFormat.FaxG4: case RasterImageFormat.FaxG32Dim: case RasterImageFormat.FaxG31Dim: case RasterImageFormat.FaxG31DimNoEol: formatFilter = "Tif files (*.tif)|*.tif"; break; case RasterImageFormat.Bmp: formatFilter = "Bmp files (*.bmp)|*.bmp"; break; case RasterImageFormat.Xbm: formatFilter = "Xbm files (*.xbm)|*.xbm"; break; case RasterImageFormat.Jpeg: case RasterImageFormat.Jpeg411: case RasterImageFormat.Jpeg422: formatFilter = "Jpeg files (*.jpg)|*.jpg"; break; case RasterImageFormat.Png: formatFilter = "Png files (*.png)|*.png"; break; case RasterImageFormat.Exif: formatFilter = "Exit files (*.exif)|*.exif"; break; case RasterImageFormat.Jbig: formatFilter = "Jbig files (*.jbg)|*.jbg"; break; } return(formatFilter); }
private RasterImageFormat GetFormat(string format, out string extension, out bool isLossless) { isLossless = false; RasterImageFormat fileFormat = RasterImageFormat.Unknown; switch (format.ToLower()) { case "bmp": fileFormat = RasterImageFormat.Bmp; extension = "bmp"; break; case "jpg lossless": fileFormat = RasterImageFormat.Jpeg; extension = "jpg"; isLossless = true; break; case "png": fileFormat = RasterImageFormat.Png; extension = "png"; break; case "tif": fileFormat = RasterImageFormat.Tif; extension = "tif"; break; case "cmp": fileFormat = RasterImageFormat.Cmp; extension = "cmp"; break; case "dicom": fileFormat = RasterImageFormat.DicomGray; extension = "dcm"; break; default: fileFormat = RasterImageFormat.Jpeg; extension = "jpg"; break; } return(fileFormat); }
private static void ConvertDocumentToImage( string inputFile, string outputFile, RasterImageFormat outputFormat, int bitsPerPixel) { if (!File.Exists(inputFile)) { throw new ArgumentException($"{inputFile} not found.", nameof(inputFile)); } if (bitsPerPixel != 0 && bitsPerPixel != 1 && bitsPerPixel != 2 && bitsPerPixel != 4 && bitsPerPixel != 8 && bitsPerPixel != 16 && bitsPerPixel != 24 && bitsPerPixel != 32) { throw new ArgumentOutOfRangeException(nameof(bitsPerPixel), bitsPerPixel, $"Invalid {nameof(bitsPerPixel)} value"); } using (var codecs = new RasterCodecs()) { codecs.Options.RasterizeDocument.Load.XResolution = 300; codecs.Options.RasterizeDocument.Load.YResolution = 300; // indicates the start of a loop from the same source file codecs.StartOptimizedLoad(); var totalPages = codecs.GetTotalPages(inputFile); if (totalPages > 1 && !RasterCodecs.FormatSupportsMultipageSave(outputFormat)) { Console.WriteLine($"The {outputFormat} format does not support multiple pages.\n" + "The resulting file will only contain the only last page of the document."); } for (var pageNumber = 1; pageNumber <= totalPages; pageNumber++) { Console.WriteLine($"Loading and saving page {pageNumber}"); using (var rasterImage = codecs.Load(inputFile, bitsPerPixel, CodecsLoadByteOrder.Bgr, pageNumber, pageNumber)) codecs.Save(rasterImage, outputFile, outputFormat, bitsPerPixel, 1, -1, 1, CodecsSavePageMode.Append); } // indicates the end of the load for the source file codecs.StopOptimizedLoad(); } }
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(); } }
void CheckForNewFiles(string inputDirectory, RasterImageFormat saveFormat) { try { if (!Directory.Exists(inputDirectory)) { return; } string[] files = Directory.GetFiles(inputDirectory); foreach (string file in files) { if (!bContinue) { break; } if (FileLocked(file)) { continue; } ConversionItem newItem = new ConversionItem(file, String.Empty, RasterImageFormat.Unknown); if (!conversionList.ContainsKey(file)) { //This is a new file. Add it to our internal list newItem.SaveFormat = saveFormat; lock (conversionListLockObj) { conversionList.Add(file, newItem); } ThreadPool.QueueUserWorkItem(new WaitCallback(ConversionProc), newItem); } } } catch (Exception ex) { //log string error = String.Format("An unexpected error has occured. Exception = {0}", ex.Message); eventLog.WriteEntry(error, EventLogEntryType.Error); } }
private ZipFile LoadInstances(List <SeriesImage> seriesImages, string userName, ExportOptions options) { ZipFile zip = null; string extension = string.Empty; bool isLossless = false; RasterImageFormat format = GetFormat(options.FileFormat, out extension, out isLossless); Dictionary <string, Dictionary <string, List <AnnContainer> > > seriesAnnotations = new Dictionary <string, Dictionary <string, List <AnnContainer> > >(); foreach (SeriesImage seriesImage in seriesImages) { string fileName = Path.ChangeExtension(Path.GetRandomFileName(), extension); if (options.BurnAnnotations) { if (!seriesAnnotations.ContainsKey(seriesImage.SeriesInstanceUID)) { seriesAnnotations[seriesImage.SeriesInstanceUID] = AddInsUtils.GetSeriesAnnotations(userName, seriesImage.SeriesInstanceUID, _QueryAddIn, _ObjectRetrieveAddIn); } if (seriesAnnotations[seriesImage.SeriesInstanceUID].ContainsKey(seriesImage.SOPInstanceUID)) { foreach (AnnContainer container in seriesAnnotations[seriesImage.SeriesInstanceUID][seriesImage.SOPInstanceUID]) { seriesImage.Image.Burn(container, seriesImage.XDpi, seriesImage.YDpi); } } } ResetGrayscale(seriesImage.Image, options.ReduceGrayscaleTo8BitsSelected); if (zip == null) { zip = new ZipFile(); } zip.AddEntry(fileName, seriesImage.Image.ToStream(format, (!isLossless && (format == RasterImageFormat.Jpeg || format == RasterImageFormat.Cmp)) ? GetCompression(options.ImageCompression) : 0)); zip.Dispose(); } return(zip); }
public void Publish(string fileName) { RasterCodecs codec = tifEditor.Codecs; RasterImage image = tifEditor.Viewer.Image; System.Windows.Forms.Cursor cursor = tifEditor.Cursor; this.tifEditor.Cursor = Cursors.WaitCursor; int totalPages = tifEditor.Viewer.Image.PageCount; RasterImageFormat format = tifEditor.Viewer.Image.OriginalFormat; AnnAutomation annAutomation = tifEditor.AnnAutomation; for (int i = 1; i <= totalPages; ++i) { tifEditor.SetPageNumber(i); tifEditor.Viewer.Refresh(); annAutomation.Realize(); } codec.Save(image, fileName, RasterImageFormat.TifxFaxG4, 0, 1, totalPages, 1, CodecsSavePageMode.Overwrite); annAutomation.Container.Objects.Clear(); this.tifEditor.Cursor = cursor; }
public static List <ImageInfo> ConvertDocumentToImage( string inputFile, string outputFileTemplate, RasterImageFormat outputFormat, int bitsPerPixel, HashSet <string> justThese) { if (justThese == null) { justThese = new HashSet <string>(); } if (!File.Exists(inputFile)) { throw new ArgumentException($"{inputFile} not found.", nameof(inputFile)); } if (bitsPerPixel != 0 && bitsPerPixel != 1 && bitsPerPixel != 2 && bitsPerPixel != 4 && bitsPerPixel != 8 && bitsPerPixel != 16 && bitsPerPixel != 24 && bitsPerPixel != 32) { throw new ArgumentOutOfRangeException(nameof(bitsPerPixel), bitsPerPixel, $"Invalid {nameof(bitsPerPixel)} value"); } var retFiles = new List <ImageInfo>(); using (var codecs = new RasterCodecs()) { codecs.Options.RasterizeDocument.Load.XResolution = 300; codecs.Options.RasterizeDocument.Load.YResolution = 300; // indicates the start of a loop from the same source file codecs.StartOptimizedLoad(); var totalPages = codecs.GetTotalPages(inputFile); /* * if (totalPages > 1 && !RasterCodecs.FormatSupportsMultipageSave(outputFormat)) * throw new NotSupportedException( * $"The {outputFormat} format does not support multiple pages."); */ for (var pageNumber = 1; pageNumber <= totalPages; pageNumber++) { string newOutfile = outputFileTemplate.Replace("{page}", pageNumber.ToString("D2")); string stem = Path.GetFileNameWithoutExtension(newOutfile); if (justThese.Count > 0 && !justThese.Contains(stem)) { continue; } if (File.Exists(newOutfile)) { logger.Info($"File already exists {newOutfile}"); retFiles.Add(new ImageInfo() { ImageFileInfo = new FileInfo(newOutfile) }); continue; } logger.Info($"Loading and saving page {newOutfile}"); var rasterImage = codecs.Load(inputFile, bitsPerPixel, CodecsLoadByteOrder.Bgr, pageNumber, pageNumber); codecs.Save(rasterImage, newOutfile, outputFormat, bitsPerPixel, 1, -1, 1, CodecsSavePageMode.Replace); retFiles.Add(new ImageInfo() { Image = rasterImage, ImageFileInfo = new FileInfo(newOutfile) }); } // indicates the end of the load for the source file codecs.StopOptimizedLoad(); } return(retFiles); }
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); } } }
private void _mnuFileSave_Click(object sender, EventArgs e) { if (_lstImagesInfoMulti == null || _lstImagesInfoMulti.Count <= 0) { Messager.ShowError(this, "Please Load Files"); return; } RasterImage img = null; Cursor cursor = this.Cursor; try { cursor = this.Cursor; this.Cursor = Cursors.WaitCursor; EnableControls(false); this._labelConverted.Text = "0"; if (_saveDialog.ShowDialog() == DialogResult.OK) { RasterImageFormat selectedformat = RasterImageFormat.CcittGroup4; if (_saveDialog.FilterIndex == 2) { selectedformat = RasterImageFormat.RasPdfG4; } _szMultiPageFile = _saveDialog.FileName; if (_mnuOptionsSingleRasterImage.Checked) { for (int i = 0; i < _lstImagesInfoMulti.Count; i++) { RasterImage loadedImage = _codecs.Load(_lstImagesInfoMulti[i].Name, 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, 1, -1); if (i == 0) { img = loadedImage; } else { img.AddPages(loadedImage, 1, -1); } _labelConverted.Text = (Convert.ToInt32(_labelConverted.Text) + 1).ToString(); Application.DoEvents(); } _codecs.Save(img, _szMultiPageFile, selectedformat, 0); img.Dispose(); } else { for (int i = 0; i < _lstImagesInfoMulti.Count; i++) { CodecsImageInfo info = _codecs.GetInformation(_lstImagesInfoMulti[i].Name, true); for (int j = 1; j <= info.TotalPages; j++) { img = _codecs.Load(_lstImagesInfoMulti[i].Name, 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, j, j); if (i == 0 && j == 1) { _codecs.Save(img, _szMultiPageFile, selectedformat, 0, 1, 1, 1, CodecsSavePageMode.Overwrite); } else { while (!ReadyToAccess(_szMultiPageFile))//Insure File is not inused by other processes { Application.DoEvents(); } _codecs.Save(img, _szMultiPageFile, selectedformat, 0, 1, 1, -1, CodecsSavePageMode.Append); } img.Dispose(); Application.DoEvents(); } _labelConverted.Text = (Convert.ToInt32(_labelConverted.Text) + 1).ToString(); info.Dispose(); Application.DoEvents(); } } Messager.ShowInformation(this, "Save in MultiPageFile Done"); } } catch (Exception ex) { Messager.ShowError(this, ex); } finally { this.Cursor = cursor; EnableControls(true); } }
public ExportImageFormat(string displayName, RasterImageFormat format, bool canReduceBitdepth, bool canPreserveBitdepth) : this(displayName, format, false, canReduceBitdepth, canPreserveBitdepth) { }
public ConversionItem(string _sourceFile, string _destFile, RasterImageFormat _saveFormat) { SourceFile = _sourceFile; DestFile = _destFile; SaveFormat = _saveFormat; }
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); } }
public TwainOperation(TwainSession twnSession, string saveLocation, RasterImageFormat format) { this.twainSession = twnSession; this.saveLocation = saveLocation; this.format = format; }
/// <summary> /// Initialize the application /// </summary> private void InitClass( ) { // setup our caption Messager.Caption = "LEADTOOLS for .NET C# Twain Multipage Demo"; Text = Messager.Caption; // initialize the _viewer object _viewer = new ImageViewer(); _viewer.Dock = DockStyle.Fill; _viewer.BackColor = Color.DarkGray; Controls.Add(_viewer); _viewer.BringToFront(); // initialize the codecs object _codecs = new RasterCodecs(); if (TwainSession.IsAvailable(this.Handle)) { try { // setup the Twain session object _twainSession = new TwainSession(); //For 32-bit driver support in 64-bit applications, use the following TWAIN initialization method instead: //_twainSession.Startup(this.Handle, "LEAD Technologies, Inc.", "LEAD Twain .NET", "Version 14", "LEADTools Twain test sample", TwainStartupFlags.UseThunkServer); // start up the Twain session _twainSession.Startup(this.Handle, "LEAD Technologies, Inc.", "LEAD Twain .NET", "Version 14", "LEADTools Twain test sample", TwainStartupFlags.None); } catch (TwainException ex) { if (ex.Code == TwainExceptionCode.InvalidDll) { _miFileAcquire.Enabled = false; _miFileAcquireCleanup.Enabled = false; _miFileSelectSource.Enabled = false; Messager.ShowError(this, "You have an old version of TWAINDSM.DLL. Please download latest version of this DLL from www.twain.org"); } else { _miFileAcquire.Enabled = false; _miFileAcquireCleanup.Enabled = false; _miFileSelectSource.Enabled = false; Messager.ShowError(this, ex); } } catch (Exception ex) { Messager.ShowError(this, ex); _miFileAcquire.Enabled = false; _miFileAcquireCleanup.Enabled = false; _miFileSelectSource.Enabled = false; } } else { _miFileAcquire.Enabled = false; _miFileAcquireCleanup.Enabled = false; _miFileSelectSource.Enabled = false; } // setup the other variables _fileName = string.Empty; _fileFormat = RasterImageFormat.Tif; _pageNo = 0; UpdateMyControls(); UpdateStatusBarText(); }
public FormatItem(RasterImageFormat f, string n) { Format = f; Name = n; }
/// <summary> /// Converts all the image file into one PDF file. /// </summary> /// <param name="imagePath">The collection of image files to combine.</param> /// <returns>True if the conversion was successful; else false.</returns> private bool ConvertImage(string[] imagePath) { try { // Get the unlock key RasterSupport.Unlock(RasterSupportType.PdfSave, _documentUnlockKey); // Startup the codecs RasterCodecs.Startup(); using (RasterCodecs codecs = new RasterCodecs()) { // Assign the codec options codecs.Options.Jpeg.Save.QualityFactor = _pdfDocumentQualityFactor; codecs.Options.Jpeg.Save.SaveWithStamp = false; codecs.Options.Jpeg.Save.StampBitsPerPixel = 0; // Set the raster image format. RasterImageFormat rasterImageFormat = RasterImageFormat.RasPdfJpeg411; // Set the pdf save type. switch (_saveType) { case PdfSaveType.PdfA: codecs.Options.Pdf.Save.SavePdfA = true; rasterImageFormat = RasterImageFormat.RasPdfJpeg; break; case PdfSaveType.Pdf14: codecs.Options.Pdf.Save.SavePdfv14 = true; rasterImageFormat = RasterImageFormat.RasPdfJpeg411; break; case PdfSaveType.Pdf15: codecs.Options.Pdf.Save.SavePdfv15 = true; rasterImageFormat = RasterImageFormat.RasPdfJpeg422; break; } // If the load tool resource path has been specified. if (!String.IsNullOrEmpty(_leadToolResPath)) { codecs.Options.Pdf.InitialPath = _leadToolResPath + "Lib;" + _leadToolResPath + "Fonts;" + _leadToolResPath + "Resource"; } // For each image file found append into the PDF document. for (int i = 0; i < imagePath.Length; i++) { // Load the image file into the image type. using (System.Drawing.Image srcImage = System.Drawing.Image.FromFile(imagePath[i])) using (RasterImage image = new RasterImage(srcImage)) { if (i > 0) { // Append each image file to the PDF document. codecs.Save(image, _pdfDocumentPath, rasterImageFormat, _pdfDocumentBitPerPixel, 1, 1, 1, CodecsSavePageMode.Append); } else { // Create or overwrite the PDF document and // place to first image at the top of the PDF. codecs.Save(image, _pdfDocumentPath, rasterImageFormat, _pdfDocumentBitPerPixel, 1, 1, 1, CodecsSavePageMode.Overwrite); } } } } // Return the result. return(true); } finally { // Shutdown the codecs RasterCodecs.Shutdown(); // If the event has been attached, then // send a complete to the client. if (OnComplete != null) { OnComplete(this, new EventArgs()); } } }
private void SetFormatAndBpp(string fileExtension) { switch (fileExtension.ToUpper()) { case ".BMP": _SaveFormat = RasterImageFormat.Bmp; BPP = 24; break; case ".DCM": _SaveFormat = RasterImageFormat.DicomColor; BPP = 24; break; case ".JPG": _SaveFormat = RasterImageFormat.Jpeg; BPP = 24; break; case ".GIF": _SaveFormat = RasterImageFormat.Gif; BPP = 8; break; case ".PNG": _SaveFormat = RasterImageFormat.Png; BPP = 24; break; default: _SaveFormat = RasterImageFormat.Bmp; BPP = 24; break; } }
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(); } }
/// <summary> /// Convert the current image to a PDF document. /// </summary> /// <returns>True if the conversion was successful; else false.</returns> private bool ConvertImage() { try { // Get the unlock key RasterSupport.Unlock(RasterSupportType.PdfSave, _documentUnlockKey); // Startup the codecs RasterCodecs.Startup(); using (RasterCodecs codecs = new RasterCodecs()) { // Load the image file into the image type. using (System.Drawing.Image srcImage = System.Drawing.Image.FromFile(_imageDocumentPath)) using (RasterImage image = new RasterImage(srcImage)) { codecs.Options.Jpeg.Save.QualityFactor = _pdfDocumentQualityFactor; codecs.Options.Jpeg.Save.SaveWithStamp = false; codecs.Options.Jpeg.Save.StampBitsPerPixel = 0; codecs.Options.Jpeg.Save.StampWidth = image.Width; codecs.Options.Jpeg.Save.StampHeight = image.Height; // Set the raster image format. RasterImageFormat rasterImageFormat = RasterImageFormat.RasPdfJpeg411; // Set the pdf save type. switch (_saveType) { case PdfSaveType.PdfA: codecs.Options.Pdf.Save.SavePdfA = true; rasterImageFormat = RasterImageFormat.RasPdfJpeg; break; case PdfSaveType.Pdf14: codecs.Options.Pdf.Save.SavePdfv14 = true; rasterImageFormat = RasterImageFormat.RasPdfJpeg411; break; case PdfSaveType.Pdf15: codecs.Options.Pdf.Save.SavePdfv15 = true; rasterImageFormat = RasterImageFormat.RasPdfJpeg422; break; } // If the load tool resource path has been specified. if (!String.IsNullOrEmpty(_leadToolResPath)) { codecs.Options.Pdf.InitialPath = _leadToolResPath + "Lib;" + _leadToolResPath + "Fonts;" + _leadToolResPath + "Resource"; } // Attempt to save the image. codecs.Save(image, _pdfDocumentPath, rasterImageFormat, _pdfDocumentBitPerPixel); } } return(true); } finally { // Shutdown the codecs RasterCodecs.Shutdown(); // If the event has been attached, then // send a complete to the client. if (OnComplete != null) { OnComplete(this, new EventArgs()); } } }