1-) C# RMOS - resimde seçili alanı crop lamak resimde seçili alanı kesmek
private Point RectStartPoint;
private Rectangle Rect = new Rectangle();
private Brush selectionBrush = new SolidBrush(Color.FromArgb(128, 72, 145, 220));
Point tempEndPoint;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
RectStartPoint = e.Location;
Invalidate();
}
else
{
Invalidate();
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
tempEndPoint = e.Location;
Rect.Location = new Point(
Math.Min(RectStartPoint.X, tempEndPoint.X),
Math.Min(RectStartPoint.Y, tempEndPoint.Y));
Rect.Size = new Size(
Math.Abs(RectStartPoint.X - tempEndPoint.X),
Math.Abs(RectStartPoint.Y - tempEndPoint.Y));
pictureBox1.Invalidate();
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Right)
{
if (Rect.Contains(e.Location))
{
float xfactor, yfactor;
xfactor = (float)(pictureBox1.Image.Width) / (float)(pictureBox1.Width);
yfactor = (float)(pictureBox1.Image.Height) / (float)(pictureBox1.Height);
Rectangle RectGecici = new Rectangle((int)(Rect.Location.X * xfactor), (int)(Rect.Location.Y * yfactor),
(int)(Rect.Size.Width * xfactor), (int)(Rect.Size.Height * yfactor));
//string buyuk = MyMain.sda.cozBitmap(cropImage(pictureBox1.Image, RectGecici));
//textBox3.Text = buyuk;
Bitmap croplananResim = cropImage(pictureBox1.Image, RectGecici);
croplananResim.Save("aa.png", ImageFormat.Png);
}
}
}
catch (Exception ex)
{
MessageBox.Show("Resim Alanının Dışında Seçim Yaptınız.! " + ex.Message);
Console.WriteLine("Alan Taşdı " + ex.Message);
}
}
private static Bitmap cropImage(System.Drawing.Image img, Rectangle cropArea)
{
Bitmap bmpImage = new Bitmap(img);
return bmpImage.Clone(cropArea, bmpImage.PixelFormat);
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
// Draw the rectangle...
if (pictureBox1.Image != null)
{
if (Rect != null && Rect.Width > 0 && Rect.Height > 0)
{
e.Graphics.FillRectangle(selectionBrush, Rect);
}
}
}