⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpegsaver.cs

📁 这是一个小型的相片管理器
💻 CS
字号:


using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace VirtualPhotoOrganizer.Photo
{
	/// <summary>
	/// Zusammenfassung f黵 JpegSaver.
	/// </summary>
	internal class JpegSaver
	{
		private ImageCodecInfo Codec = null;

		public JpegSaver() {
			// initialize our codec var
			ImageCodecInfo[] codecList = ImageCodecInfo.GetImageDecoders();
			foreach (ImageCodecInfo i in codecList) {
				if (i.MimeType == "image/jpeg")	// have we found the JPEG codec?
				{
					Codec = i;
					break;
				}
			}
		}

		/// <summary>
		/// offers the user the possiblility to take further actions if no JPEG codec was found
		/// </summary>
		public bool FoundJpegCodec {
			get {
				if (Codec != null)
					return true;
				else
					return false;
			}
		}


		/// <summary>
		/// Saves the specified Bitmap under the specified name, with the specified quality (1 = lowest, 100 = highest)
		/// </summary>
		public void SaveJpeg(string path, Bitmap image, int quality) {
			// if we were unable to find the JPEG codec, we'll use the standard .NET quality setting of 75
			if (Codec == null)
				image.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
			else	// use the specified quality
			{
				EncoderParameters ep = new EncoderParameters();
				ep.Param[0] = new EncoderParameter(Encoder.Quality, quality);
				image.Save(path, Codec, ep);
				ep.Dispose();
			}
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -