こんばんは。
http://komin1.cool.ne.jp/retouch/tone_curve.htm
の様に「摘んでぐにゃーっと曲がる描写の仕方」と言う事でしょうか。
取り敢えずpictureBox1(256x256の大きさを推奨), textBox1, textBox2が必要です。以下参考程度に。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
//マウスが押されている
private Boolean bCapture;
//ツマミの位置
private Point ptHotSpot;
//表示されるビットマップ
private Image imgCanvas;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//ピクチャボックスに合わせてビットマップを作成する
Size size = this.pictureBox1.Size;
this.imgCanvas = new Bitmap(size.Width, size.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
//初期化
this.bCapture = false;
//ツマミの位置を中央に持ってくる
this.ptHotSpot = new Point(this.imgCanvas.Width / 2, this.imgCanvas.Height / 2);
this.DrawToneCurve(this.ptHotSpot);
this.UpdateText(this.ptHotSpot);
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(this.imgCanvas, 0, 0, this.imgCanvas.Width, this.imgCanvas.Height);
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
//ツマミの位置から+-4の範囲に収まっていなければ摘ませない
if( e.X < this.ptHotSpot.X - 4 ||
e.Y < this.ptHotSpot.Y - 4 ||
e.X > this.ptHotSpot.X + 4 ||
e.Y > this.ptHotSpot.Y + 4)
return;
//マウスが押されている
this.bCapture = true;
//最新のマウス位置をツマミ位置に記憶してカーブを描いてテキストボックスを更新する
this.ptHotSpot = new Point(e.X, e.Y);
this.DrawToneCurve(this.ptHotSpot);
this.UpdateText(this.ptHotSpot);
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
//マウスが放された
this.bCapture = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (!this.bCapture)
return;
//最新のマウス位置をツマミ位置に記憶してカーブを描いてテキストボックスを更新する
this.ptHotSpot = new Point(e.X, e.Y);
this.DrawToneCurve(this.ptHotSpot);
this.UpdateText(this.ptHotSpot);
}
private void DrawToneCurve(Point point)
{
//カーブを描く為の座標配列
Point[] points = new Point[3] { new Point(this.imgCanvas.Height, 0), point, new Point(0, this.imgCanvas.Width) };
Graphics gfx = Graphics.FromImage(this.imgCanvas);
//ビットマップを塗り潰す
gfx.FillRectangle(Brushes.AliceBlue, new Rectangle(0, 0, this.imgCanvas.Width, this.imgCanvas.Height));
//カーブを描く
gfx.DrawCurve(Pens.DarkOliveGreen, points);
//ツマミ位置+-4の大きさでツマミを描く
gfx.FillRectangle(Brushes.DeepSkyBlue, new Rectangle(this.ptHotSpot.X - 4, this.ptHotSpot.Y - 4, 8, 8));
//リソースの始末
gfx.Dispose();
//ピクチャボックスを再描画させる
this.pictureBox1.Invalidate();
}
private void UpdateText(Point point)
{
this.textBox1.Text = point.X.ToString();
this.textBox2.Text = point.Y.ToString();
}
}
}
お礼
ありがとうございます! こちらを参考にして作ってみようと思います。