Wasn't that easy to dispose the Image, since this
img.dispose() does not only dispose the img alone but since its referenced also by the pictureBox.Image which still is needed (thats why the invalid paramter exceptions are thrown after dispose() i mentioned before).Code:this.pb_map.Image = img;
Took me a while until i saw that.
Now I'm doing it this way:
Now I can't reproduce the OoM-Exception but to be honest, I can't believe that this solution is the best (I don't like to copy or to clone...) so I'm asking what do you think about this idea?Code://if no Image exists on Picture Box, create one (looks like the source) if (this.pb_map.Image == null) { this.pb_map.Image = (Image)img.Clone(); //Make it not the Image itself but a clone of it (so im can be disposed) } g = Graphics.FromImage(this.pb_map.Image); //create Graphics Object //draw area g.DrawImage(img, x * 32, y * 32, new Rectangle(this.runtime.Selector.X * 32, this.runtime.Selector.Y * 32, 32, 32), GraphicsUnit.Pixel); img.Dispose();




Reply With Quote
