|
|
|
C# โปรแกรมจัดการเกี่ยวกับรูปภาพช่วยแนะนำวิธีการ crop ภาพ |
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TextBoxTest
{
public partial class Form1 : Form
{
Point startPos; // mouse-down position
Point currentPos; // current mouse position
bool drawing; // busy drawing
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
currentPos = Point.Empty;
startPos = Point.Empty;
drawing = false;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
PictureBox pbImage = (PictureBox)sender;
pbImage.Refresh();
currentPos = e.Location;
startPos = e.Location;
drawing = true;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
PictureBox pbImage = (PictureBox)sender;
if (drawing)
{
currentPos = e.Location;
pbImage.Refresh();
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
PictureBox pbImage = (PictureBox)sender;
if (drawing)
{
drawing = false;
pbImage.Refresh();
if (currentPos != startPos)
MessageBox.Show(string.Format("x: {0}, y: {1}, w: {2}, h: {3}",
Math.Min(startPos.X, currentPos.X),
Math.Min(startPos.Y, currentPos.Y),
Math.Abs(startPos.X - currentPos.X),
Math.Abs(startPos.Y - currentPos.Y)), "Rectangle", MessageBoxButtons.OK);
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Rectangle rectangle = new Rectangle(
Math.Min(startPos.X, currentPos.X),
Math.Min(startPos.Y, currentPos.Y),
Math.Abs(startPos.X - currentPos.X),
Math.Abs(startPos.Y - currentPos.Y));
using (Brush brush = new SolidBrush(Color.FromArgb(128, 100, 149, 237)))
{
if (startPos != Point.Empty)
{
e.Graphics.DrawRectangle(Pens.CornflowerBlue, rectangle);
e.Graphics.FillRectangle(brush, rectangle);
}
if (drawing)
{
e.Graphics.DrawRectangle(Pens.CornflowerBlue, rectangle);
e.Graphics.FillRectangle(brush, rectangle);
}
}
}
}
}
|
|
|
|
|
Date :
2016-03-07 16:50:53 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|