الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Crop Image And Out Of Memory Exception

بدأه yummy في 23 مارس 2009 · 1 رد · 584 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

قمت بعمل method تقوم بعمل crop لجزء من الصورة ووضعة كاخلقية الform ولكن عند تكرار هذا الكود اكثر من مرة بشكل متتالي يظهر exceptionكالتالي out of memory exception لادري ما الاخطاء في هذا الكود ارجو المساعدة

public Bitmap CropBitmap(Bitmap bitmap, int cropX, int cropY, int cropWidth, int cropHeight)

{

Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);

Bitmap cropped = bitmap.Clone(rect, bitmap.PixelFormat);

return cropped;

}

bitmap my_map=new bitmap(this.backgroundimage);

This.Backgroundimage=(Image)CropBitmap(my_mapm,e.X,e.Y,50,50);

#2

مرحباً أخي الكريم,

جرب استبدال العملية المذكورة في الأعلى بالتالية :

 

[color= #000000; font-weight: bold;]public Bitmap CropImage[color= #009900;](Bitmap _Bitmap[color= #339933;], int _Left[color= #339933;], int _Top[color= #339933;], int _Width[color= #339933;], int _Height[color= #009900;])

[color= #009900;]{

    bool Acceptable [color= #339933;]= [color= #000000; font-weight: bold;]false[color= #339933;];

    Acceptable [color= #339933;]= [color= #009900;]([color= #009900;](_Left [color= #339933;]>= [color= #cc66cc;]0[color= #009900;]) [color= #339933;]& [color= #009900;](_Top [color= #339933;]>= [color= #cc66cc;]0[color= #009900;])[color= #009900;])[color= #339933;];

    int CW [color= #339933;]= [color= #cc66cc;]0[color= #339933;];

    int CH [color= #339933;]= [color= #cc66cc;]0[color= #339933;];

    CW [color= #339933;]= [color= #009900;](_Top [color= #339933;]+ _Width[color= #009900;])[color= #339933;];

    CH [color= #339933;]= [color= #009900;](_Top [color= #339933;]+ _Height[color= #009900;])[color= #339933;];

    Acceptable [color= #339933;]= Acceptable [color= #339933;]& [color= #009900;]([color= #009900;]([color= #009900;](_Width [color= #339933;]> [color= #cc66cc;]0[color= #009900;]) [color= #339933;]& [color= #009900;](CW [color= #339933;]<= _Bitmap[color= #339933;].Width[color= #009900;])[color= #009900;]) [color= #339933;]& [color= #009900;]([color= #009900;](_Height [color= #339933;]> [color= #cc66cc;]0[color= #009900;]) [color= #339933;]& [color= #009900;](CH [color= #339933;]<=
 _Bitmap[color= #339933;].Height[color= #009900;])[color= #009900;])[color= #009900;])[color= #339933;];

    [color= #b1b100;]if [color= #009900;](Acceptable[color= #009900;]) [color= #009900;]{

        [color= #b1b100;]return _Bitmap[color= #339933;].Clone[color= #009900;]([color= #000000; font-weight: bold;]new Rectangle[color= #009900;](_Left[color= #339933;], _Top[color= #339933;], _Width[color= #339933;], _Height[color= #009900;])[color= #339933;], _Bitmap[color= #339933;].PixelFormat[color= #009900;])[color= #339933;];

    [color= #009900;]}

    [color= #b1b100;]else [color= #009900;]{

        throw [color= #000000; font-weight: bold;]new Exception[color= #009900;]([color= #0000ff;]"Error !"[color= #009900;])[color= #339933;];

    [color= #009900;]}

[color= #009900;]}

بالتوفيق

The important thing is not so much

that every child should be taught,

as that every child should be given the wish to learn.

مواضيع مشابهة