cropassistant.cs
来自「这是一个小型的相片管理器」· CS 代码 · 共 65 行
CS
65 行
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 + =
减小字号Ctrl + -
显示快捷键?