Winform my button to reset my picturebox and fill it in with a new generated image is not working
https://hatebin.com/cslhmvmnya - my code
Lines 121-124 is the methos to reset the picturebox but Im unsure how to do this
it uses a Graphic From Image, then uses imported from file images
13 Replies
What does not work there?
I can only assume when and what error there can be.
For instance, you're not disposing the
Image
of the PictureBox
, but the PictureBox
box itself on Line 116
, which leads to an exception trying to access a disposed object.
Usually in WinForms you Clear
the image, by disposing it first, since it's a common memory leak mistake. Do it with something like this:
Try not to dispose the Control
, but the Bitmap
object inside it.im not sure whats not working, i disposed and set the picturebox to null so it must be what is set on the picturebox that is not resetting itself
somewhere between lines 73-88 I'd assume
So, what is your desired result?
that when i press the reset button i can change the images position without it keeping the original image
Okay, what do you mean by "change the images position"?
i made a way that the user can chose the x, y and size
and im trying to make it possible to reset the image cause of original icon is still there afterword
If you dispose and clear the picturebox's
Image
like I described it's fine.There's no problem in
GenerateCard
and the image should save and clear the Picturebox
by adding pboxGEN.Image = null;
on line 116.
After this, you can recreate an image and altering the x,y,width & heightweird i tried it and still keeps original image over
I would guess your dialogs are holding the images hostage at this point
u dont dispose of a single dialog after u use them
i'll look into it
i disposed them, same result
ok i got some new results, when in my program if I open file dialogs again and chose the same images and generate it again (without using my reset button) it removes the old Image and adds the new one
but how come they keep my original image if I dont reopen file dialogs?
I did some testing, the problem is that it keeps the stream alive so its always modifying the stream your loading in memory that's why it never wipes it.
What u want to do is, use a Bitmap, and manipulate that bitmap.
For example:
And