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

📄 cropassistant.cs

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

using System;
using System.Drawing;
using System.Windows.Forms;
using VirtualPhotoOrganizer.Photo;

namespace VirtualPhotoOrganizer.Photo
{
	/// <summary>
	/// Handles all the little assets of cropping an image - used by the photo viewer
	/// </summary>
	internal class CropAssistant
	{
		// the brush, which we'll need
		SolidBrush GrayB;

		public CropAssistant() {
			GrayB = new SolidBrush(Color.Gray);
		}

		/// <summary>
		/// returns a bitmap, where the specified crop area is grayed out
		/// </summary>
		public void GetCropPreview(Bitmap b, int top, int bottom, int left, int right) {
			Graphics g = Graphics.FromImage(b);

			// gray out the cropped areas
			CropTop(b, g, top);
			CropBottom(b, g, bottom);
			CropLeft(b, g, left);
			CropRight(b, g, right);

			g.Dispose();
		}

		/// <summary>
		/// draws a gray rectangle over the area that is supposed to be cropped from the top
		/// </summary>
		private void CropTop(Bitmap b, Graphics g, int pixels) {
			g.FillRectangle(GrayB, 0, 0, b.Width, pixels);
		}

		/// <summary>
		/// draws a gray rectangle over the area that is supposed to be cropped from the top
		/// </summary>
		private void CropBottom(Bitmap b, Graphics g, int pixels) {
			g.FillRectangle(GrayB, 0, b.Height - pixels, b.Width, pixels);
		}

		/// <summary>
		/// draws a gray rectangle over the area that is supposed to be cropped from the top
		/// </summary>
		private void CropLeft(Bitmap b, Graphics g, int pixels) {
			g.FillRectangle(GrayB, 0, 0, pixels, b.Height);
		}

		/// <summary>
		/// draws a gray rectangle over the area that is supposed to be cropped from the top
		/// </summary>
		private void CropRight(Bitmap b, Graphics g, int pixels) {
			g.FillRectangle(GrayB, b.Width - pixels, 0, pixels, b.Height);
		}
	}
}

⌨️ 快捷键说明

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