[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Drawing Image and Disposing image from PictureBox

Adam Edell via DotNetMonster.com

1/17/2005 9:36:00 AM

Hi everyone,
I have two questions if you like to help me a little

I'm using PictureBox control on my PocketPC application.
I have drawing and displaying in PictureBox.

1. Is it good method to all drawing, cleaning and stuff doing in other
place(some other bitmap, graphics..) and then simply draw result in PictureBox? How to do that?

2. How to use Dispose on PictureBox images?

I have method clearBox()..and clearing an image from the screen on control I'm doing with

pictureBox1.Image = null;

But, I suppose that resource stay in memory. How to clear memory from images that don't display using PictureBox. I was trying with

pictureBox.Image.Dispose()

but I'm getting NullReferenceException

thanx

Marko

--
Message posted via http://www.dotnetm...
1 Answer

Morten Wennevik [C# MVP]

1/17/2005 11:21:00 AM

0

On Mon, 17 Jan 2005 09:35:55 GMT, marko v via DotNetMonster.com
<forum@DotNetMonster.com> wrote:

> Hi everyone,
> I have two questions if you like to help me a little
>
> I'm using PictureBox control on my PocketPC application.
> I have drawing and displaying in PictureBox.
>
> 1. Is it good method to all drawing, cleaning and stuff doing in other
> place(some other bitmap, graphics..) and then simply draw result in
> PictureBox? How to do that?
>

This method works fine. You can use Graphics.FromImage to create a
graphics object from a bitmap and draw directly onto the bitmap using the
Graphics methods.

> 2. How to use Dispose on PictureBox images?
>

You need to obtain a reference to the image and clear it from the
PictureBox before disposing it.

Image i = picbox.Image;
picbox.Image = null;
i.Dispose();


> I have method clearBox()..and clearing an image from the screen on
> control I'm doing with
> pictureBox1.Image = null;
>
> But, I suppose that resource stay in memory. How to clear memory from
> images that don't display using PictureBox. I was trying with
>
> pictureBox.Image.Dispose()
>
> but I'm getting NullReferenceException
>

You cannot call dispose after setting the image to null, or do anything to
something that is set to null. See above to see how to dispose of the
image.

> thanx
>
> Marko
>

I'm not sure if it is necessary to dispose of an internally created
Bitmap. As long as it does not hold a file open it should be fine to just
set it to null and forget about it. Maybe someone can clarify.

--
Happy Coding!
Morten Wennevik [C# MVP]