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

📄 resizedialog.cs

📁 一个C#开发的类似PHOTOSHOP的软件,用到了很多图形算法.
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -