/// <summary>
        /// Save image to a local filename
        /// </summary>
        /// <param name="exportType"></param>
        /// <returns></returns>
        public bool SaveToFile(ImageExportType exportType)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            switch (exportType)
            {
            case ImageExportType.Png:
                sfd.Filter = "Png files (*.png)|*.png|All files (*.*)|*.*";
                break;

            default:
                throw new NotSupportedException();
            }
            sfd.FilterIndex = 1;

            if (sfd.ShowDialog() == false)
            {
                return(false);
            }


            using (Stream stream = sfd.OpenFile())
            {
                byte[] binaryData = GetBytes(exportType);
                stream.Write(binaryData, 0, binaryData.Length);

                stream.Close();
            }

            return(true);
        }
Example #2
0
        private void DoExportUsingFlexCelImgExportSimple(ImageColorDepth ColorDepth)
        {
            if (!HasFileOpen())
            {
                return;
            }
            if (!LoadPreferences())
            {
                return;
            }

            if (exportImageDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            ImageExportType ImgFormat = ImageExportType.Png;

            if (String.Compare(Path.GetExtension(exportImageDialog.FileName), ".jpg", true) == 0)
            {
                ImgFormat = ImageExportType.Jpeg;
            }

            using (FlexCelImgExport ImgExport = new FlexCelImgExport(flexCelPrintDocument1.Workbook))
            {
                ImgExport.AllVisibleSheets           = cbAllSheets.Checked;
                ImgExport.ResetPageNumberOnEachSheet = cbResetPageNumber.Checked;
                ImgExport.Resolution = 96; //To get a better quality image but with larger file size too, increate this value. (for example to 300 or 600 dpi)
                ImgExport.SaveAsImage(exportImageDialog.FileName, ImgFormat, ColorDepth);
            }
        }
Example #3
0
 public void SaveAsImage(string fileName, ImageExportType export, ImageColorDepth ColorDepth)
 {
     try
     {
         FileMode fm = FileMode.CreateNew;
         if (AllowOverwritingFiles)
         {
             fm = FileMode.Create;
         }
         using (FileStream f = new FileStream(fileName, fm, FileAccess.Write))
         {
             SaveAsImage(f, export, ColorDepth);
         }
     }
     catch (IOException)
     {
         //Don't delete the file in an io exception. It might be because allowoverwritefiles was false, and the file existed.
         throw;
     }
     catch
     {
         File.Delete(fileName);
         throw;
     }
 }
        /// <summary>
        /// Process the record
        /// </summary>
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            try
            {
                ImageExportType record = ExportCustomerImage();

                if (record != null)
                {
                    WriteObject(record);
                }
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
// if (e is HttpRequestException)
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }
        }
 private static byte[] GetBytesInternal(UIElement element, ImageExportType exportType)
 {
     switch (exportType)
     {
     case ImageExportType.Png:
         return(GetBytesInternalPng(element));
     }
     throw new NotSupportedException();
 }
Example #6
0
        /// <summary>
        /// Save image to a local filename
        /// </summary>
        /// <param name="exportType"></param>
        /// <returns></returns>
        public bool SaveToFile(ImageExportType exportType)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            switch (exportType)
            {
            case ImageExportType.Png:
                sfd.Filter = "Png files (*.png)|*.png|All files (*.*)|*.*";
                break;

            case ImageExportType.Jpg:
                sfd.Filter = "Jpg files (*.jpg)|*.jpg|All files (*.*)|*.*";
                break;

            default:
                throw new NotSupportedException();
            }
            sfd.FilterIndex = 1;

            if (sfd.ShowDialog() == false)
            {
                return(false);
            }

            if (exportType == ImageExportType.Png)
            {
                using (Stream stream = sfd.OpenFile())
                {
                    byte[] binaryData = GetBytes(exportType);
                    stream.Write(binaryData, 0, binaryData.Length);

                    stream.Close();
                }
            }
            else if (exportType == ImageExportType.Jpg)
            {
                //ExtendedImage myImage = new ExtendedImage();

                // JpegEncoder jpeg = new JpegEncoder();
                //jpeg.Encode(
                //ExtendedImage img = new ExtendedImage();
                //using (Image img = Image.FromStream(new MemoryStream(raw)))
                //{
                //    img.Save("foo.jpg", ImageFormat.Jpeg);
                //}
            }

            return(true);
        }
Example #7
0
        //How to create a multipage tiff using FlexCelImgExport.
        //This will create a multipage tiff with the data.
        private void DoExportMultiPageTiff(ImageColorDepth ColorDepth, bool IsFax)
        {
            if (!HasFileOpen())
            {
                return;
            }
            if (!LoadPreferences())
            {
                return;
            }

            if (exportTiffDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            ImageExportType ExportType = ImageExportType.Tiff;

            if (IsFax)
            {
                ExportType = ImageExportType.Fax;
            }

            using (FlexCelImgExport ImgExport = new FlexCelImgExport(flexCelPrintDocument1.Workbook))
            {
                ImgExport.AllVisibleSheets           = cbAllSheets.Checked;
                ImgExport.ResetPageNumberOnEachSheet = cbResetPageNumber.Checked;

                ImgExport.Resolution = 96; //To get a better quality image but with larger file size too, increate this value. (for example to 300 or 600 dpi)
                using (FileStream TiffStream = new FileStream(exportTiffDialog.FileName, FileMode.Create))
                {
                    ImgExport.SaveAsImage(TiffStream, ExportType, ColorDepth);
                }
            }
            if (MessageBox.Show("Do you want to open the generated file?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Process.Start(exportTiffDialog.FileName);
            }
        }
Example #8
0
        public void SaveAsImage(Stream fileStream, ImageExportType export, ImageColorDepth ColorDepth)
        {
            if (Workbook == null)
            {
                FlxMessages.ThrowException(FlxErr.ErrWorkbookNull);
            }
            Workbook.Recalc(false);

            switch (export)
            {
            case ImageExportType.Tiff:
                CreateMultiPageTiff(fileStream, ColorDepth, export);
                break;

            case ImageExportType.Fax:
                CreateMultiPageTiff(fileStream, ColorDepth, export);
                break;

            case ImageExportType.Fax4:
                CreateMultiPageTiff(fileStream, ColorDepth, export);
                break;

            case ImageExportType.Gif:
                CreateImg(fileStream, ImageFormat.Gif, ImageColorDepth.Color256);
                break;

            case ImageExportType.Png:
                CreateImg(fileStream, ImageFormat.Png, ColorDepth);
                break;

            case ImageExportType.Jpeg:
                CreateImg(fileStream, ImageFormat.Jpeg, ColorDepth);
                break;

            default: FlxMessages.ThrowException(FlxErr.ErrInvalidImageFormat);
                break;
            }
        }
 /// <summary>
 /// Returns a raw byte array of image
 /// </summary>
 /// <param name="exportType"></param>
 /// <returns></returns>
 public byte[] GetBytes(ImageExportType exportType)
 {
     return(GetBytesInternal(this, exportType));
 }
Example #10
0
 //07-06-2012 - Adicionado por Felipe Soares
 /// <summary>
 /// Save image to a local filename
 /// </summary>
 /// <param name="exportType"></param>
 /// <returns></returns>
 public byte[] GetBytesAsExportType(ImageExportType exportType)
 {
     return(GetBytes(exportType));
 }
Example #11
0
        private void CreateMultiPageTiff(Stream OutStream, ImageColorDepth ColorDepth, ImageExportType ExportType)
        {
            ImageCodecInfo info = GetTiffEncoder();

            int ParamCount = 1;

            if (ExportType == ImageExportType.Fax || ExportType == ImageExportType.Fax4)
            {
                ParamCount++;
            }

            EncoderParameters ep = new EncoderParameters(ParamCount);

            ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.MultiFrame);

            bool IsFax = false;

            switch (ExportType)
            {
            case ImageExportType.Fax:
                ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT3);
                IsFax       = true;
                break;

            case ImageExportType.Fax4:
                ep.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
                IsFax       = true;
                break;
            }

            bool Is1bpp = IsFax || ColorDepth == ImageColorDepth.BlackAndWhite;

            TImgExportInfo ExportInfo = null;

            PixelFormat RgbPixFormat = IsFax || ColorDepth != ImageColorDepth.TrueColor ? PixelFormat.Format32bppPArgb : PixelFormat.Format24bppRgb;
            PixelFormat PixFormat    = PixelFormat.Format1bppIndexed;

            if (!IsFax)
            {
                switch (ColorDepth)
                {
                case ImageColorDepth.TrueColor: PixFormat = RgbPixFormat; break;

                case ImageColorDepth.Color256: PixFormat = PixelFormat.Format8bppIndexed; break;
                }
            }

            using (Bitmap OutImg = CreateBitmap(Resolution, ref ExportInfo, PixFormat))
            {
                //First image is handled differently.
                Bitmap ActualOutImg = Is1bpp || ColorDepth != ImageColorDepth.TrueColor ? CreateBitmap(Resolution, ref ExportInfo, RgbPixFormat) : OutImg;
                try
                {
                    using (Graphics Gr = Graphics.FromImage(ActualOutImg))
                    {
                        Gr.FillRectangle(Brushes.White, 0, 0, ActualOutImg.Width, ActualOutImg.Height); //Clear the background
                        ExportNext(Gr, ref ExportInfo);
                    }

                    if (Is1bpp)
                    {
                        FloydSteinbergDither.ConvertToBlackAndWhite(ActualOutImg, OutImg);
                    }
                    else
                    if (!IsFax && ColorDepth == ImageColorDepth.Color256)
                    {
                        OctreeQuantizer.ConvertTo256Colors(ActualOutImg, OutImg);
                    }
                }
                finally
                {
                    if (ActualOutImg != OutImg)
                    {
                        ActualOutImg.Dispose();
                    }
                }

                OutImg.Save(OutStream, info, ep);
                ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.FrameDimensionPage);


                //Now the rest of images.
                ExportInfo = ExportAllImagesButFirst(ep, Is1bpp, ExportInfo, RgbPixFormat, OutImg, ColorDepth);

                ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.SaveFlag, (long)EncoderValue.Flush);
                OutImg.SaveAdd(ep);
            }
        }