resizedialog.cs
来自「一个C#开发的类似PHOTOSHOP的软件,用到了很多图形算法.」· CS 代码 · 共 79 行
CS
79 行
using System;
using System.Drawing;
using System.Windows.Forms;
namespace PhotoSprite.Dialog
{
public partial class ResizeDialog : Form
{
double aspectRatio = 1.3333;
bool locked = false;
public ResizeDialog(Bitmap b)
{
InitializeComponent();
aspectRatio = (double)b.Width / (double)b.Height;
this.widthUpDown.Value = b.Width;
this.heightUpDown.Value = b.Height;
}
private void widthUpDown_ValueChanged(object sender, EventArgs e)
{
if (locked) return;
if (this.constrainCheckBox.Checked)
{
locked = true;
this.heightUpDown.Value = (int)((double)this.widthUpDown.Value / aspectRatio + 0.5);
locked = false;
}
}
private void heightUpDown_ValueChanged(object sender, EventArgs e)
{
if (locked) return;
if (this.constrainCheckBox.Checked)
{
locked = true;
this.widthUpDown.Value = (int)((double)this.heightUpDown.Value * aspectRatio + 0.5);
locked = false;
}
}
/// <summary>
/// 获取或设置图像调整后宽度
/// </summary>
public int NewWidth
{
get
{
return (int)widthUpDown.Value;
}
set
{
widthUpDown.Value = value;
}
}
/// <summary>
/// 获取或设置图像调整后高度
/// </summary>
public int NewHeight
{
get
{
return (int)heightUpDown.Value;
}
set
{
heightUpDown.Value = value;
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?