using System;
using System.Drawing;
using System.Windows.Forms;
namespace ImageEditing
{
public partial class frmPaintTool : Form
{
// 変数
// ビットマップ画像
Bitmap _newBitMap;
// マウスクリック中のフラグ
bool _mouseDrug;
// 前のマウスカーソルのX、Y座標
int _prevX;
int _prevY;
public frmPaintTool()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// BitMapオブジェクトを生成する
_newBitMap = new Bitmap(DrawingPicBox.Width, DrawingPicBox.Height);
}
private void DrawingPicBox_MouseDown(object sender, MouseEventArgs e)
{
// マウスクリック開始判定
_mouseDrug = true;
// マウスカーソル位置記憶の初期化
_prevX = e.Location.X;
_prevY = e.Location.Y;
}
private void DrawingPicBox_MouseUp(object sender, MouseEventArgs e)
{
// マウスクリック終了判定
_mouseDrug = false;
}
private void DrawingPicBox_MouseMove(object sender, MouseEventArgs e)
{
// マウスクリック中に、BitMapにGraphicsオブジェクトで描画する
if (_mouseDrug == true)
{
// BitMapからGraphicsオブジェクトを生成
//描画に利用するペンの色、太さを設定
//指定したペンでマウスの位置に線を引く
Graphics objGrp = Graphics.FromImage(_newBitMap);
Pen objPen = new Pen(Color.Black, 3);
objGrp.DrawLine(objPen, _prevX, _prevY, e.Location.X, e.Location.Y);
_prevX = e.Location.X;
_prevY = e.Location.Y;
objPen.Dispose();
objGrp.Dispose();
// BitMapオブジェクトをPictureBoxに表示する
DrawingPicBox.Image = _newBitMap;
}
}
}
private void btnReverse_Click(object sender, EventArgs e)
{
// 「左右反転」ボタンが押されたとき
_newBitMap.RotateFlip(RotateFlipType.Rotate180FlipY);
DrawingPicBox.Image = _newBitMap;
}
}