The bottom line is that during the MouseMove event, the application in RAM starts to occupy 1GB and more, and even after the end of this event continues to occupy so much space. What and how can I fix it? My program draws lines and rectangles, over the image, as well as cuts and saves a fragment in the picturebox.
static Point^ pointstart = gcnew Point(0,0); static array<Point>^ Points = gcnew array<Point>(100000); static int i=1, j=0, proverka=0, xs, ys, xe, ye; static array<Bitmap^>^ reserv=gcnew array<Bitmap^>(100); private: System::Void picture_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { if (proverka!=0) { if (type == 1 || type == 3) { picture->Image = reserv[j-1]; xe=Convert::ToInt32(e->X); ye=Convert::ToInt32(e->Y); pointstart->X = Convert::ToInt64(e->X); pointstart->Y = Convert::ToInt64(e->Y); Points-> SetValue (pointstart, i); if (i!=1) { Bitmap^ pic = gcnew Bitmap (picture->Image); Graphics^ g = Graphics::FromImage(pic); array<Point>^ PointsDraw = gcnew array<Point>(i); Array::Copy(Points, PointsDraw, i); g->DrawCurve(newpen, PointsDraw); picture->Image = pic; Array::Clear(PointsDraw, 0, i); } xs=xe; ys=ye; i++; } if (type == 2 || type == 4) { picture->Image = reserv[j-1]; int xw, yw; xe=Convert::ToInt32(e->X); ye=Convert::ToInt32(e->Y); if (xs < xe && ys < ye ) { xw = xe - xs; yw = ye - ys; } else { xw = xe - xs; yw = ye - ys; xs = xe; ys = ye; } Bitmap^ pic = gcnew Bitmap (picture->Image); Graphics^ g = Graphics::FromImage(pic); g->DrawRectangle(newpen, xs, ys, abs(xw), abs(yw)); picture->Image = pic; } } } private: System::Void picture_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) { if (proverka!=0) { if (type == 1 || type == 3) { picture->Image = reserv[j-1]; //Задание точек pointstart->X = Convert::ToInt64(e->X); pointstart->Y = Convert::ToInt64(e->Y); Points-> SetValue (pointstart, i); array<Point>^ PointsDraw = gcnew array<Point>(i); Array::Copy(Points, PointsDraw, i); //Рисование Bitmap^ pic = gcnew Bitmap(picture->Image); Graphics^ g = Graphics::FromImage(pic); g->DrawCurve(newpen, PointsDraw); picture->Image = pic; //Сохранение reserv->SetValue (pic, j); j++; //Возвращение к начальным значениям Array::Clear(Points, 0, Points->Length); Array::Clear(PointsDraw, 0, i); i=1; proverka=0; } if (type == 2) { picture->Image = reserv[j-1]; int xw, yw; xe=Convert::ToInt32(e->X); ye=Convert::ToInt32(e->Y); if (xs < xe && ys < ye ) { xw = xe - xs; yw = ye - ys; } else { xw = xe - xs; yw = ye - ys; xs = xe; ys = ye; } Bitmap^ pic = gcnew Bitmap (picture->Image); Graphics^ g = Graphics::FromImage(pic); g->DrawRectangle(newpen, xs, ys, abs(xw), abs(yw)); picture->Image = pic; //Сохранение reserv->SetValue (pic, j); j++; //К начальным данным proverka = 0; i=1; } if (type == 4) { picture->Image = reserv[j-1]; int xw, yw; xe=Convert::ToInt32(e->X); ye=Convert::ToInt32(e->Y); if (xs < xe && ys < ye ) { xw = xe - xs; yw = ye - ys; } else { xw = xe - xs; yw = ye - ys; xs = xe; ys = ye; } Bitmap^ pic = gcnew Bitmap(picture->Image); Rectangle cloneRect = Rectangle(xs, ys, xw, yw); picture->Image = pic->Clone(cloneRect, pic->PixelFormat); Bitmap^ save = gcnew Bitmap(picture->Image); reserv->SetValue (save, j); j++; } } }
picture_MouseMove
is called very often. At least 10 times per second. if theproverka
not zero, then in seconds 10 "mouse movements" the array will be to the eye. - KoVadim 2:19 pm