Esempio n. 1
0
        private void SetExportParams(
            NuGenProgressBar progressBar
            , Image[] images
            , NuGenImageType imageType
            , NuGenImageFileFormat fileFormat
            , bool numWatermark
            , Font watermarkFont
            , Color watermarkColor
            , ContentAlignment watermarkAlign
            , string path
            , string template
            )
        {
            Debug.Assert(progressBar != null, "progressBar != null");
            Debug.Assert(images != null, "images != null");

            _exportProgressBar.Minimum = 0;
            _exportProgressBar.Maximum =
                images.Length
                * NuGenEnum.FlagsSetOn(imageType)
                * NuGenEnum.FlagsSetOn(fileFormat)
            ;
            _exportProgressBar.Style = NuGenProgressBarStyle.Marquee;
            _exportProgressBar.Value = 0;

            _exportImages         = images;
            _exportImageType      = imageType;
            _exportFileFormat     = fileFormat;
            _exportNumWatermark   = numWatermark;
            _exportWatermarkFont  = watermarkFont;
            _exportWatermarkColor = watermarkColor;
            _exportWatermarkAlign = watermarkAlign;
            _exportPath           = path;
            _exportTemplate       = template;
        }
Esempio n. 2
0
        public void Export(
            Image image
            , NuGenImageType imageType
            , NuGenImageFileFormat fileFormat
            , Size resolution
            , string path
            , string filename
            )
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException("filename");
            }

            image = NuGenControlPaint.GetThumbnail(image, resolution);

            if ((imageType & NuGenImageType.Color) != 0)
            {
                this.ExportToFileFormat(
                    image,
                    fileFormat,
                    path,
                    string.Format("{0}_Color", filename)
                    );
            }

            if ((imageType & NuGenImageType.Grayscale) != 0)
            {
                this.ExportToFileFormat(
                    NuGenControlPaint.GetDesaturatedImage(image),
                    fileFormat,
                    path,
                    string.Format("{0}_Grayscale", filename)
                    );
            }

            if ((imageType & NuGenImageType.Monochrome) != 0)
            {
                this.ExportToFileFormat(
                    NuGenControlPaint.GetMonochromeImage(image),
                    fileFormat,
                    path,
                    string.Format("{0}_Monochrome", filename)
                    );
            }
        }
		/// <summary>
		/// Exports the specified image to the specified file formats and types.
		/// </summary>
		/// <param name="image">Specifies the image to export.</param>
		/// <param name="imageType">Specifies image types (i.e. color, grayscale, monochrome).</param>
		/// <param name="resolution">Specifies the resolution for the image.</param>
		/// <param name="fileFormat">Specifies file formats (i.e. BMP, JPEG, etc).</param>
		/// <param name="path">Specifies destination directory.</param>
		/// <param name="filename">Specifies the string that is used in the filename pattern.</param>
		/// <exception cref="T:System.ArgumentNullException">
		/// <para><paramref name="image"/> is <see langword="null"/>.</para>
		/// -or-
		/// <para><paramref name="path"/> is <see langword="null"/> or empty string.</para>
		/// -or-
		/// <para><paramref name="filename"/> is <see langword="null"/> or empty string.</para>
		/// </exception>
		/// <exception cref="T:System.ArgumentException">
		/// Width or height of the <paramref name="resolution"/> structure are not positive.
		/// </exception>
		public void Export(Image image, NuGenImageType imageType, NuGenImageFileFormat fileFormat, Size resolution, string path, string filename)
		{
			if (image == null)
			{
				throw new ArgumentNullException("image");
			}

			if (string.IsNullOrEmpty(path))
			{
				throw new ArgumentNullException("path");
			}

			if (string.IsNullOrEmpty(filename))
			{
				throw new ArgumentNullException("filename");
			}

			image = NuGenControlPaint.GetThumbnail(image, resolution);

			if ((imageType & NuGenImageType.Color) != 0)
			{
				this.ExportToFileFormat(
					(Bitmap)image,
					fileFormat,
					path,
					string.Format("{0}_Color", filename)
					);
			}

			if ((imageType & NuGenImageType.Grayscale) != 0)
			{
				this.ExportToFileFormat(
					NuGenControlPaint.GetGrayscaleBitmap((Bitmap)image),
					fileFormat,
					path,
					string.Format("{0}_Grayscale", filename)
					);
			}

			if ((imageType & NuGenImageType.Monochrome) != 0)
			{
				this.ExportToFileFormat(
					NuGenControlPaint.GetMonochromeBitmap((Bitmap)image),
					fileFormat,
					path,
					string.Format("{0}_Monochrome", filename)
					);
			}
		}
Esempio n. 4
0
        public void ExportWithWatermark(
            Image image
            , NuGenImageType imageType
            , NuGenImageFileFormat fileFormat
            , Size resolution
            , int watermarkCount
            , Font watermarkFont
            , Color watermarkColor
            , ContentAlignment watermarkAlignment
            , string path
            , string filename
            )
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            if (watermarkFont == null)
            {
                throw new ArgumentNullException("watermarkFont");
            }

            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException("filename");
            }

            using (Graphics g = Graphics.FromImage(image))
                using (SolidBrush sb = new SolidBrush(watermarkColor))
                {
                    string    text            = watermarkCount.ToString(CultureInfo.CurrentCulture);
                    Size      watermarkSize   = g.MeasureString(text, watermarkFont).ToSize();
                    Rectangle watermarkBounds = NuGenControlPaint.ImageBoundsFromContentAlignment(
                        watermarkSize
                        , new Rectangle(new Point(0, 0), image.Size)
                        , watermarkAlignment
                        );
                    g.DrawString(text, watermarkFont, sb, watermarkBounds);
                }

            this.Export(image, imageType, fileFormat, resolution, path, filename);
        }
		public void ExportWithWatermark(
			Image image
			, NuGenImageType imageType
			, NuGenImageFileFormat fileFormat
			, Size resolution
			, int watermarkCount
			, Font watermarkFont
			, Color watermarkColor
			, ContentAlignment watermarkAlignment
			, string path
			, string filename
			)
		{
			if (image == null)
			{
				throw new ArgumentNullException("image");
			}

			if (watermarkFont == null)
			{
				throw new ArgumentNullException("watermarkFont");
			}

			if (string.IsNullOrEmpty(path))
			{
				throw new ArgumentNullException("path");
			}

			if (string.IsNullOrEmpty(filename))
			{
				throw new ArgumentNullException("filename");
			}

			using (Graphics g = Graphics.FromImage(image))
			using (SolidBrush sb = new SolidBrush(watermarkColor))
			{
				string text = watermarkCount.ToString(CultureInfo.CurrentCulture);
				Size watermarkSize = g.MeasureString(text, watermarkFont).ToSize();
				Rectangle watermarkBounds = NuGenControlPaint.ImageBoundsFromContentAlignment(
					watermarkSize
					, new Rectangle(new Point(0, 0), image.Size)
					, watermarkAlignment
				);
				g.DrawString(text, watermarkFont, sb, watermarkBounds);
			}

			this.Export(image, imageType, fileFormat, resolution, path, filename);
		}
		/// <summary>
		/// Shows the dialog to the user.
		/// </summary>
		/// <param name="image">Specifies the image to export.</param>
		/// <param name="imageType">Specifies image types (i.e. color, grayscale, monochrome).</param>
		/// <param name="resolution">Specifies the resolution for the image.</param>
		/// <param name="fileFormat">Specifies file formats (i.e. BMP, JPEG, etc).</param>
		/// <param name="path">Specifies destination directory.</param>
		/// <param name="filename">Specifies the string that is used in the filename pattern.</param>
		/// <exception cref="T:System.ArgumentNullException">
		/// <paramref name="image"/> is <see langword="null"/>.
		/// </exception>
		/// <exception cref="T:System.ArgumentException">
		/// <para>
		///		Width or height of the <paramref name="resolution"/> structure are not positive.
		/// </para>
		/// -or-
		/// <para>
		///		<paramref name="path"/> is <see langword="null"/> or an empty string.
		/// </para>
		/// -or-
		/// <para>
		///		<paramref name="filename"/> is <see langword="null"/> or an empty string.
		/// </para>
		/// </exception>
		public void ShowDialog(
			Image image,
			NuGenImageType imageType,
			NuGenImageFileFormat fileFormat,
			Size resolution,
			string path,
			string filename
			)
		{
			if (image == null)
			{
				throw new ArgumentNullException("image");
			}

			this.SetProgressBarParams(_progressBar, imageType, fileFormat);

			NuGenImageExport export = new NuGenImageExport();
			export.Progress += this.exportProgress;

			ExportDelegate exportDelegate = new ExportDelegate(export.Export);
			exportDelegate.BeginInvoke(
				image,
				imageType,
				fileFormat,
				resolution,
				path,
				filename,
				new AsyncCallback(
					delegate
					{
						if (this.IsHandleCreated)
						{
							this.BeginInvoke(new MethodInvoker(
								delegate
								{
									this.Close();
								})
							);
						}
					}
				),
				null
			);

			base.ShowDialog();
		}
Esempio n. 7
0
        private void ExportToFileFormat(Image img, NuGenImageFileFormat fileFormat, string path, string filename)
        {
            Debug.Assert(img != null, "bmp != null");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if ((fileFormat & NuGenImageFileFormat.Bmp) != 0)
            {
                img.Save(this.GetUniqueFileName(path, filename, "bmp", 0), ImageFormat.Bmp);

                if (!this.ShouldContinue())
                {
                    return;
                }
            }

            if ((fileFormat & NuGenImageFileFormat.Emf) != 0)
            {
                img.Save(this.GetUniqueFileName(path, filename, "emf", 0), ImageFormat.Emf);

                if (!this.ShouldContinue())
                {
                    return;
                }
            }

            if ((fileFormat & NuGenImageFileFormat.Exif) != 0)
            {
                img.Save(this.GetUniqueFileName(path, filename, "exif", 0), ImageFormat.Exif);

                if (!this.ShouldContinue())
                {
                    return;
                }
            }

            if ((fileFormat & NuGenImageFileFormat.Gif) != 0)
            {
                img.Save(this.GetUniqueFileName(path, filename, "gif", 0), ImageFormat.Gif);

                if (!this.ShouldContinue())
                {
                    return;
                }
            }

            if ((fileFormat & NuGenImageFileFormat.Jpeg) != 0)
            {
                img.Save(this.GetUniqueFileName(path, filename, "jpg", 0), ImageFormat.Jpeg);

                if (!this.ShouldContinue())
                {
                    return;
                }
            }

            if ((fileFormat & NuGenImageFileFormat.Png) != 0)
            {
                img.Save(this.GetUniqueFileName(path, filename, "png", 0), ImageFormat.Png);

                if (!this.ShouldContinue())
                {
                    return;
                }
            }

            if ((fileFormat & NuGenImageFileFormat.Tiff) != 0)
            {
                img.Save(this.GetUniqueFileName(path, filename, "tiff", 0), ImageFormat.Tiff);

                if (!this.ShouldContinue())
                {
                    return;
                }
            }

            if ((fileFormat & NuGenImageFileFormat.Wmf) != 0)
            {
                img.Save(this.GetUniqueFileName(path, filename, "wmf", 0), ImageFormat.Wmf);

                if (!this.ShouldContinue())
                {
                    return;
                }
            }
        }
		private void ExportToFileFormat(Bitmap bmp, NuGenImageFileFormat fileFormat, string path, string filename)
		{
			Debug.Assert(bmp != null, "bmp != null");

			if (!Directory.Exists(path))
			{
				Directory.CreateDirectory(path);
			}

			if ((fileFormat & NuGenImageFileFormat.Bmp) != 0)
			{
				bmp.Save(this.GetUniqueFileName(path, filename, "bmp", 0), ImageFormat.Bmp);
				
				if (!this.ShouldContinue())
				{
					return;
				}
			}

			if ((fileFormat & NuGenImageFileFormat.Emf) != 0)
			{
				bmp.Save(this.GetUniqueFileName(path, filename, "emf", 0), ImageFormat.Emf);

				if (!this.ShouldContinue())
				{
					return;
				}
			}

			if ((fileFormat & NuGenImageFileFormat.Exif) != 0)
			{
				bmp.Save(this.GetUniqueFileName(path, filename, "exif", 0), ImageFormat.Exif);

				if (!this.ShouldContinue())
				{
					return;
				}
			}

			if ((fileFormat & NuGenImageFileFormat.Gif) != 0)
			{
				bmp.Save(this.GetUniqueFileName(path, filename, "gif", 0), ImageFormat.Gif);

				if (!this.ShouldContinue())
				{
					return;
				}
			}

			if ((fileFormat & NuGenImageFileFormat.Jpeg) != 0)
			{
				bmp.Save(this.GetUniqueFileName(path, filename, "jpg", 0), ImageFormat.Jpeg);

				if (!this.ShouldContinue())
				{
					return;
				}
			}

			if ((fileFormat & NuGenImageFileFormat.Png) != 0)
			{
				bmp.Save(this.GetUniqueFileName(path, filename, "png", 0), ImageFormat.Png);

				if (!this.ShouldContinue())
				{
					return;
				}
			}

			if ((fileFormat & NuGenImageFileFormat.Tiff) != 0)
			{
				bmp.Save(this.GetUniqueFileName(path, filename, "tiff", 0), ImageFormat.Tiff);

				if (!this.ShouldContinue())
				{
					return;
				}
			}

			if ((fileFormat & NuGenImageFileFormat.Wmf) != 0)
			{
				bmp.Save(this.GetUniqueFileName(path, filename, "wmf", 0), ImageFormat.Wmf);

				if (!this.ShouldContinue())
				{
					return;
				}
			}
		}
		private void SetProgressBarParams(ProgressBar progressBar, NuGenImageType imageType, NuGenImageFileFormat fileFormat)
		{
			Debug.Assert(progressBar != null, "progressBar != null");

			progressBar.Minimum = 0;
			progressBar.Maximum = NuGenEnum.FlagsSetOn(imageType) * NuGenEnum.FlagsSetOn(fileFormat);
		}