示例#1
0
        //Use this load to load an image using the open dialog
        public int Load(IWin32Window owner, RasterCodecs codecs, bool autoLoad)
        {
            using (RasterOpenDialog ofd = new RasterOpenDialog(codecs))
            {
                ofd.DereferenceLinks             = true;
                ofd.CheckFileExists              = false;
                ofd.CheckPathExists              = true;
                ofd.EnableSizing                 = true;
                ofd.Filter                       = Filters;
                ofd.FilterIndex                  = _filterIndex;
                ofd.LoadFileImage                = false;
                ofd.LoadOptions                  = false;
                ofd.LoadRotated                  = true;
                ofd.LoadCompressed               = true;
                ofd.LoadMultithreaded            = codecs.Options.Jpeg.Load.Multithreaded;
                ofd.ShowLoadMultithreaded        = true;
                ofd.Multiselect                  = _multiSelect;
                ofd.ShowGeneralOptions           = true;
                ofd.ShowLoadCompressed           = true;
                ofd.ShowLoadOptions              = true;
                ofd.ShowLoadRotated              = true;
                ofd.ShowMultipage                = true;
                ofd.UseGdiPlus                   = UseGdiPlus;
                ofd.ShowPdfOptions               = ShowPdfOptions;
                ofd.ShowXpsOptions               = ShowXpsOptions;
                ofd.ShowXlsOptions               = ShowXlsOptions;
                ofd.ShowRasterizeDocumentOptions = ShowRasterizeDocumentOptions;
                ofd.EnableFileInfoModeless       = true;
                ofd.EnableFileInfoResizing       = true;
                ofd.ShowVffOptions               = ShowVffOptions;
                ofd.ShowAnzOptions               = ShowAnzOptions;
                ofd.ShowVectorOptions            = ShowVectorOptions;
                ofd.ShowPreview                  = true;
                ofd.ShowProgressive              = true;
                ofd.ShowRasterOptions            = true;
                ofd.ShowTotalPages               = true;
                ofd.ShowDeletePage               = true;
                ofd.ShowFileInformation          = true;
                ofd.UseFileStamptoPreview        = true;
                ofd.PreviewWindowVisible         = true;
                ofd.Title         = "LEADTOOLS Open Dialog";
                ofd.FileName      = FileName;
                ofd.LoadCorrupted = LoadCorrupted;
                ofd.PreferVector  = PreferVector;
                if (!String.IsNullOrEmpty(_openDialogInitialPath))
                {
                    ofd.InitialDirectory = _openDialogInitialPath;
                }

                if (ofd.ShowDialog(owner) == DialogResult.OK)
                {
                    foreach (RasterDialogFileData item in ofd.OpenedFileData)
                    {
                        FileName = item.Name;

                        _filterIndex = ofd.FilterIndex;

                        // Set the RasterizeDocument load options before calling GetInformation
                        codecs.Options.RasterizeDocument.Load.PageWidth    = item.Options.RasterizeDocumentOptions.PageWidth;
                        codecs.Options.RasterizeDocument.Load.PageHeight   = item.Options.RasterizeDocumentOptions.PageHeight;
                        codecs.Options.RasterizeDocument.Load.LeftMargin   = item.Options.RasterizeDocumentOptions.LeftMargin;
                        codecs.Options.RasterizeDocument.Load.TopMargin    = item.Options.RasterizeDocumentOptions.TopMargin;
                        codecs.Options.RasterizeDocument.Load.RightMargin  = item.Options.RasterizeDocumentOptions.RightMargin;
                        codecs.Options.RasterizeDocument.Load.BottomMargin = item.Options.RasterizeDocumentOptions.BottomMargin;
                        codecs.Options.RasterizeDocument.Load.Unit         = item.Options.RasterizeDocumentOptions.Unit;
                        codecs.Options.RasterizeDocument.Load.XResolution  = item.Options.RasterizeDocumentOptions.XResolution;
                        codecs.Options.RasterizeDocument.Load.YResolution  = item.Options.RasterizeDocumentOptions.YResolution;
                        codecs.Options.RasterizeDocument.Load.SizeMode     = item.Options.RasterizeDocumentOptions.SizeMode;

                        if (item.FileInfo.Format == RasterImageFormat.Afp || item.FileInfo.Format == RasterImageFormat.Ptoca)
                        {
                            codecs.Options.Ptoka.Load.Resolution = codecs.Options.RasterizeDocument.Load.XResolution;
                        }

                        // Set the user Options
                        codecs.Options.Load.Passes             = item.Passes;
                        codecs.Options.Load.Rotated            = item.LoadRotated;
                        codecs.Options.Load.Compressed         = item.LoadCompressed;
                        codecs.Options.Load.LoadCorrupted      = ofd.LoadCorrupted;
                        codecs.Options.Load.PreferVector       = ofd.PreferVector;
                        codecs.Options.Jpeg.Load.Multithreaded = item.LoadMultithreaded;

                        switch (item.Options.FileType)
                        {
                        case RasterDialogFileOptionsType.Meta:
                        {
                            // Set the user options
                            codecs.Options.Wmf.Load.XResolution = item.Options.MetaOptions.XResolution;
                            codecs.Options.Wmf.Load.YResolution = item.Options.MetaOptions.XResolution;
                            break;
                        }

                        case RasterDialogFileOptionsType.Pdf:
                        {
                            if (codecs.Options.Pdf.Load.UsePdfEngine)
                            {
                                // Set the user options
                                codecs.Options.Pdf.Load.DisplayDepth  = item.Options.PdfOptions.DisplayDepth;
                                codecs.Options.Pdf.Load.GraphicsAlpha = item.Options.PdfOptions.GraphicsAlpha;
                                codecs.Options.Pdf.Load.TextAlpha     = item.Options.PdfOptions.TextAlpha;
                                codecs.Options.Pdf.Load.UseLibFonts   = item.Options.PdfOptions.UseLibFonts;
                            }

                            break;
                        }

                        case RasterDialogFileOptionsType.Misc:
                        {
                            switch (item.FileInfo.Format)
                            {
                            case RasterImageFormat.Jbig:
                            {
                                // Set the user options
                                codecs.Options.Jbig.Load.Resolution = new LeadSize(item.Options.MiscOptions.XResolution,
                                                                                   item.Options.MiscOptions.YResolution);
                                break;
                            }

                            case RasterImageFormat.Cmw:
                            {
                                // Set the user options
                                codecs.Options.Jpeg2000.Load.CmwResolution = new LeadSize(item.Options.MiscOptions.XResolution,
                                                                                          item.Options.MiscOptions.YResolution);
                                break;
                            }

                            case RasterImageFormat.Jp2:
                            {
                                // Set the user options
                                codecs.Options.Jpeg2000.Load.Jp2Resolution = new LeadSize(item.Options.MiscOptions.XResolution,
                                                                                          item.Options.MiscOptions.YResolution);
                                break;
                            }

                            case RasterImageFormat.J2k:
                            {
                                // Set the user options
                                codecs.Options.Jpeg2000.Load.J2kResolution = new LeadSize(item.Options.MiscOptions.XResolution,
                                                                                          item.Options.MiscOptions.YResolution);
                                break;
                            }
                            }

                            break;
                        }

                        case RasterDialogFileOptionsType.Xls:
                        {
                            // Set the user options
                            codecs.Options.Xls.Load.MultiPageSheet  = item.Options.XlsOptions.MultiPageSheet;
                            codecs.Options.Xls.Load.ShowHiddenSheet = item.Options.XlsOptions.ShowHiddenSheet;
#if LEADTOOLS_V20_OR_LATER
                            codecs.Options.Xls.Load.MultiPageUseSheetWidth = item.Options.XlsOptions.MultiPageUseSheetWidth;
                            codecs.Options.Xls.Load.PageOrderDownThenOver  = item.Options.XlsOptions.PageOrderDownThenOver;
                            codecs.Options.Xls.Load.MultiPageEnableMargins = item.Options.XlsOptions.MultiPageEnableMargins;
#endif //#if LEADTOOLS_V20_OR_LATER
                        }
                        break;

                        case RasterDialogFileOptionsType.Vff:
                        {
                            codecs.Options.Vff.Load.View = item.Options.VffOptions.View;
                            break;
                        }

                        case RasterDialogFileOptionsType.Anz:
                        {
                            codecs.Options.Anz.Load.View = item.Options.AnzOptions.View;
                            break;
                        }

                        case RasterDialogFileOptionsType.Vector:
                        {
                            codecs.Options.Vector.Load.BackgroundColor      = item.Options.VectorOptions.Options.BackgroundColor;
                            codecs.Options.Vector.Load.BitsPerPixel         = item.Options.VectorOptions.Options.BitsPerPixel;
                            codecs.Options.Vector.Load.ForceBackgroundColor = item.Options.VectorOptions.Options.ForceBackgroundColor;
                            codecs.Options.Vector.Load.ViewHeight           = item.Options.VectorOptions.Options.ViewHeight;
                            codecs.Options.Vector.Load.ViewMode             = item.Options.VectorOptions.Options.ViewMode;
                            codecs.Options.Vector.Load.ViewWidth            = item.Options.VectorOptions.Options.ViewWidth;
                            break;
                        }
                        }

                        int firstPage = 1;
                        int lastPage  = 1;
                        int infoTotalPages;

                        CodecsImageInfo info = null;

                        using (WaitCursor wait = new WaitCursor())
                        {
                            info           = codecs.GetInformation(FileName, true);
                            infoTotalPages = info.TotalPages;
                        }

                        if (_showLoadPagesDialog)
                        {
                            firstPage = 1;
                            lastPage  = infoTotalPages;

                            if (firstPage != lastPage)
                            {
                                using (ImageFileLoaderPagesDialog dlg = new ImageFileLoaderPagesDialog(infoTotalPages, LoadOnlyOnePage))
                                {
                                    if (dlg.ShowDialog(owner) == DialogResult.OK)
                                    {
                                        firstPage = dlg.FirstPage;
                                        lastPage  = dlg.LastPage;
                                    }
                                    else
                                    {
                                        if (info != null)
                                        {
                                            info.Dispose();
                                        }
                                        return(0);
                                    }
                                }
                            }
                        }
                        else
                        {
                            firstPage = item.PageNumber;
                            lastPage  = item.PageNumber;
                        }

                        _firstPage = firstPage;
                        _lastPage  = lastPage;

                        if (!SetDocumentLoadResultion(codecs, info, firstPage, lastPage))
                        {
                            info.Dispose();
                            return(0);
                        }

                        if (autoLoad)
                        {
                            using (WaitCursor wait = new WaitCursor())
                            {
                                _image = codecs.Load(FileName, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage);
                                if (codecs.LoadStatus != RasterExceptionCode.Success)
                                {
                                    String message = String.Format("The image was only partially loaded due to error: {0}", codecs.LoadStatus.ToString());
                                    Messager.Show(null, message, MessageBoxIcon.Information, MessageBoxButtons.OK);
                                }
                                if (_image != null)
                                {
                                    _image.CustomData.Add("IsBigTiff", info.Tiff.IsBigTiff);
                                    _images.Add(new ImageInformation(_image, item.Name));
                                }
                            }
                        }
                        info.Dispose();
                    }
                }

                return(ofd.OpenedFileData.Count);
            }
        }
示例#2
0
        public bool Load(IWin32Window owner, RasterCodecs codecs, bool autoLoad)
        {
#if LEADTOOLS_V16_OR_LATER && !LEADTOOLS_V17_OR_LATER
            // Load using the RasterizeDocument options
            codecs.Options.RasterizeDocument.Load.Enabled = true;
#endif

            RasterOpenDialog ofd = new RasterOpenDialog(codecs);

            ofd.DereferenceLinks      = true;
            ofd.CheckFileExists       = false;
            ofd.CheckPathExists       = true;
            ofd.EnableSizing          = true;
            ofd.Filter                = Filters;
            ofd.FilterIndex           = _filterIndex;
            ofd.LoadFileImage         = false;
            ofd.LoadOptions           = false;
            ofd.LoadRotated           = true;
            ofd.LoadCompressed        = true;
            ofd.Multiselect           = false;
            ofd.ShowGeneralOptions    = true;
            ofd.ShowLoadCompressed    = true;
            ofd.ShowLoadOptions       = true;
            ofd.ShowLoadRotated       = true;
            ofd.ShowMultipage         = true;
            ofd.ShowPdfOptions        = true;
            ofd.ShowPreview           = true;
            ofd.ShowProgressive       = true;
            ofd.ShowRasterOptions     = true;
            ofd.ShowTotalPages        = true;
            ofd.ShowDeletePage        = true;
            ofd.ShowFileInformation   = true;
            ofd.UseFileStamptoPreview = true;
            ofd.PreviewWindowVisible  = true;
            ofd.Title    = "LEADTOOLS Open Dialog";
            ofd.FileName = FileName;
#if LEADTOOLS_V16_OR_LATER
            ofd.ShowRasterizeDocumentOptions = true;
            ofd.ShowXlsOptions = true;
#endif
            bool ok = false;

            if (ofd.ShowDialog(owner) == DialogResult.OK)
            {
                RasterDialogFileData firstItem = ofd.OpenedFileData[0] as RasterDialogFileData;
                FileName = firstItem.Name;

                ok = true;

                _filterIndex = ofd.FilterIndex;

                CodecsImageInfo info;

                using (WaitCursor wait = new WaitCursor())
                    info = codecs.GetInformation(FileName, true);

                if (info.Format == RasterImageFormat.RasPdf ||
                    info.Format == RasterImageFormat.RasPdfG31Dim ||
                    info.Format == RasterImageFormat.RasPdfG32Dim ||
                    info.Format == RasterImageFormat.RasPdfG4 ||
                    info.Format == RasterImageFormat.RasPdfJpeg ||
                    info.Format == RasterImageFormat.RasPdfJpeg422 ||
                    info.Format == RasterImageFormat.RasPdfJpeg411)
                {
                    if (!codecs.Options.Pdf.IsEngineInstalled)
                    {
#if !LEADTOOLS_V17_OR_LATER
                        PdfEngineDialog dlg = new PdfEngineDialog();
                        if (dlg.ShowDialog(owner) != DialogResult.OK)
                        {
                            return(false);
                        }
#endif
                    }
                }

#if LEADTOOLS_V16_OR_LATER
                // Set the RasterizeDocument load options before calling GetInformation
#if !LEADTOOLS_V17_OR_LATER
                codecs.Options.RasterizeDocument.Load.Enabled = firstItem.Options.RasterizeDocumentOptions.Enabled;
#endif
                codecs.Options.RasterizeDocument.Load.PageWidth    = firstItem.Options.RasterizeDocumentOptions.PageWidth;
                codecs.Options.RasterizeDocument.Load.PageHeight   = firstItem.Options.RasterizeDocumentOptions.PageHeight;
                codecs.Options.RasterizeDocument.Load.LeftMargin   = firstItem.Options.RasterizeDocumentOptions.LeftMargin;
                codecs.Options.RasterizeDocument.Load.TopMargin    = firstItem.Options.RasterizeDocumentOptions.TopMargin;
                codecs.Options.RasterizeDocument.Load.RightMargin  = firstItem.Options.RasterizeDocumentOptions.RightMargin;
                codecs.Options.RasterizeDocument.Load.BottomMargin = firstItem.Options.RasterizeDocumentOptions.BottomMargin;
                codecs.Options.RasterizeDocument.Load.Unit         = firstItem.Options.RasterizeDocumentOptions.Unit;
                codecs.Options.RasterizeDocument.Load.XResolution  = firstItem.Options.RasterizeDocumentOptions.XResolution;
                codecs.Options.RasterizeDocument.Load.YResolution  = firstItem.Options.RasterizeDocumentOptions.YResolution;
                codecs.Options.RasterizeDocument.Load.SizeMode     = firstItem.Options.RasterizeDocumentOptions.SizeMode;
#endif

                // Set the user Options
                codecs.Options.Load.Passes     = firstItem.Passes;
                codecs.Options.Load.Rotated    = firstItem.LoadRotated;
                codecs.Options.Load.Compressed = firstItem.LoadCompressed;
                _FileFormatType = firstItem.Options.FileType;

                switch (firstItem.Options.FileType)
                {
                case RasterDialogFileOptionsType.Meta:
                {
                    // Set the user options
                    codecs.Options.Wmf.Load.XResolution = firstItem.Options.MetaOptions.XResolution;
                    codecs.Options.Wmf.Load.YResolution = firstItem.Options.MetaOptions.XResolution;

                    break;
                }

                case RasterDialogFileOptionsType.Pdf:
                {
                    if (codecs.Options.Pdf.IsEngineInstalled)
                    {
#if !LEADTOOLS_V175_OR_LATER
                        if (!_firstPdfLoaded)
                        {
                            PdfDPIOptions DPIOptions = new PdfDPIOptions();

                            if (DPIOptions.ShowDialog() == DialogResult.OK)
                            {
                                codecs.Options.Pdf.Load.XResolution = DPIOptions.XResolution;
                                codecs.Options.Pdf.Load.YResolution = DPIOptions.YResolution;
                                _firstPdfLoaded = true;
                            }
                            else
                            {
                                codecs.Options.Pdf.Load.XResolution = 150;
                                codecs.Options.Pdf.Load.YResolution = 150;
                            }
                        }
                        else
                        {
                            // Set the user options
                            codecs.Options.Pdf.Load.DisplayDepth  = firstItem.Options.PdfOptions.DisplayDepth;
                            codecs.Options.Pdf.Load.GraphicsAlpha = firstItem.Options.PdfOptions.GraphicsAlpha;
                            codecs.Options.Pdf.Load.TextAlpha     = firstItem.Options.PdfOptions.TextAlpha;
                            codecs.Options.Pdf.Load.UseLibFonts   = firstItem.Options.PdfOptions.UseLibFonts;
                        }
#endif
                    }

                    break;
                }

                case RasterDialogFileOptionsType.Misc:
                {
                    switch (firstItem.FileInfo.Format)
                    {
                    case RasterImageFormat.Jbig:
                    {
                        // Set the user options
                        codecs.Options.Jbig.Load.Resolution = new LeadSize(firstItem.Options.MiscOptions.XResolution,
                                                                           firstItem.Options.MiscOptions.YResolution);
                        break;
                    }

                    case RasterImageFormat.Cmw:
                    {
                        // Set the user options
                        codecs.Options.Jpeg2000.Load.CmwResolution = new LeadSize(firstItem.Options.MiscOptions.XResolution,
                                                                                  firstItem.Options.MiscOptions.YResolution);
                        break;
                    }

                    case RasterImageFormat.Jp2:
                    {
                        // Set the user options
                        codecs.Options.Jpeg2000.Load.Jp2Resolution = new LeadSize(firstItem.Options.MiscOptions.XResolution,
                                                                                  firstItem.Options.MiscOptions.YResolution);
                        break;
                    }

                    case RasterImageFormat.J2k:
                    {
                        // Set the user options
                        codecs.Options.Jpeg2000.Load.J2kResolution = new LeadSize(firstItem.Options.MiscOptions.XResolution,
                                                                                  firstItem.Options.MiscOptions.YResolution);
                        break;
                    }
                    }

                    break;
                }
                }

                int firstPage = 1;
                int lastPage  = 1;

                if (ShowLoadPagesDialog)
                {
                    firstPage = 1;
                    lastPage  = info.TotalPages;

                    if (firstPage != lastPage)
                    {
                        ImageFileLoaderPagesDialog dlg = new ImageFileLoaderPagesDialog(info.TotalPages, LoadOnlyOnePage);
                        if (dlg.ShowDialog(owner) == DialogResult.OK)
                        {
                            firstPage = dlg.FirstPage;
                            lastPage  = dlg.LastPage;
                        }
                        else
                        {
                            ok = false;
                        }
                    }
                }
                else
                {
                    firstPage = firstItem.PageNumber;
                    lastPage  = firstItem.PageNumber;
                }

                _firstPage = firstPage;
                _lastPage  = lastPage;

                if (autoLoad && ok)
                {
                    using (WaitCursor wait = new WaitCursor())
                    {
                        _image = codecs.Load(FileName, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage);
                    }
                }
            }

            return(ok);
        }