/// <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. 2
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();
		}
		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);
		}