PDA

View Full Version : سوال: کراپ کردن تصویر



hamid_73
یک شنبه 03 فروردین 1393, 15:51 عصر
سلام دوستان

int x, y, x2, y2;
bool state = false;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
state = true;
x = e.X;
y = e.Y;
}

private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (state == true)
{
Graphics a = pictureBox1.CreateGraphics();
pictureBox1.Refresh();
a.DrawRectangle(Pens.Red, x, y, e.X, e.Y);
}
}

private static Image cropImage(Image img, Rectangle cropArea)
{
Bitmap bmpImage = new Bitmap(img);
Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
return (Image)(bmpCrop);
}

private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
state = false;
Graphics a = pictureBox1.CreateGraphics();
pictureBox1.Refresh();
System.Drawing.Drawing2D.HatchBrush Br = new System.Drawing.Drawing2D.HatchBrush(System.Drawing .Drawing2D.HatchStyle.Weave, Color.Red, Color.Transparent);
a.FillRectangle(Br, x, y, e.X, e.Y);
a.DrawRectangle(Pens.Blue, x, y, e.X, e.Y);
pictureBox2.Image = cropImage(pictureBox1.Image, new Rectangle(x +36 , y + 100, e.X + 160, e.Y + 350));
}




دوستان این کد کراپ کردنه تصویره
وقتی یک تیکه از عکس رو با موس انتخاب می کنی روی این خط ارور میده
Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
میزنه out of memory چیکار کنم

hamid_73
یک شنبه 03 فروردین 1393, 23:41 عصر
کسی نمیدونه ارور واسه چیه؟

plus
دوشنبه 04 فروردین 1393, 01:51 صبح
بازه ای که به متد Clone میدین خارج از محدوده Bitmap هست.

Clone() may also throw an Out of memory exception when the coordinates specified in the Rectangle are outside the bounds of the bitmap. It will not clip them automatically for you.

hamid_73
دوشنبه 04 فروردین 1393, 10:52 صبح
خب باید چیکار کنم؟

hamid_73
دوشنبه 04 فروردین 1393, 13:32 عصر
دوستان کمک کنید
چیکار کنم که دیگه همچین اروری که دوستمون گفته رو نده

iman_me
دوشنبه 04 فروردین 1393, 14:31 عصر
از این سورس استفاده کن

hamid_73
دوشنبه 04 فروردین 1393, 14:44 عصر
از این سورس استفاده کن

این سورسم که همون ارور رو میده

iman_me
دوشنبه 04 فروردین 1393, 14:46 عصر
پس مشکل از یه جای دیگه اس از سورس نیس
چون واسه من هیچ اروری نمیده

hamid_73
دوشنبه 04 فروردین 1393, 15:38 عصر
وقتی از سمته چپ به راست درگ می کنی یه تیکه رو میگیره وقتی از راست به چپ میگیری ارو میده