Re: Bitmap .net GDI+

Andrew Dunn <[email protected]> Mon, 30 Jul 2007 15:57:26 +1000
Newsgroups gmane.comp.windows.devel.dotnet.web
Message-ID <5B2CE496DCCE2040B271D9417E72CB2822BD83@bdbdc2.corporate.hcn.com.au>
Hi,

I read this: http://blogs.msdn.com/ericgu/archive/2003/12/08/52964.aspx

I need to do this quite a lot (assign picturebox.image property) so I am
worried about memory not being cleaned up. 

What I think I may do is create a class that encapsulates a bitmap
object (from your directions). From this class I can scale, crop etc.
and when I need to assign a picturebox.image property I return something
like this...

public class ImageWrapper:IDisposable{

        private Bitmap _OriginalImg;

        public Bitmap OriginalImg
        {
                get{return new Bitmap(_OriginalImg);}
                set{_OriginalImg = value;}
        }

        public void Scale(){
                .......
        }
        public void Crop(){
                .......
        }

        public void Dispose(){
                .......
                _OriginalImg.Dispose();
        }	

} 

Does this sound feasible?

Regards,

Andrew

-----Original Message-----
From: Discussion of building .NET applications targeted for the Web
[mailto:[email protected]] On Behalf Of Gyorgy Bozoki
Sent: Monday, 30 July 2007 3:44 PM
To: [email protected]
Subject: Re: [DOTNET-WEB] Bitmap .net GDI+

Andrew,

I think that would cause a lot of trouble for you - if you try to do
this in
a web project, you'll have concurrency issues (multiple threads might
want
to use the same image, so you'd have to use extensive locking.) Also,
creating the image on disk would be very expensive in terms of
performance.

Why do you need to return a bitmap from a call to an outside caller? (Or
in
other words, do you actually need to return a bitmap?) My experience is
that
a class rarely needs to return a bitmap that it creates internally. Most
operations can be done by the same class (and outside callers can just
call
public methods to perform those operations, so they don't actually need
the
bitmap.) When the caller is done, the original class can save the bitmap
to
some storage.

In case you actually need to return the bitmap (because the caller wants
to
save it, for example), then I'd just return a copy of it, so the
ownership
of the original doesn't change. If the creator class is not needed
anymore,
it'll be thrown away at it'll then free up the bitmap. If it's needed,
then
it'll need its bitmap to stay intact.

HTH,
Gyorgy Bozoki

> -----Original Message-----
> From: Discussion of building .NET applications targeted for
> the Web [mailto:[email protected]] On Behalf Of
> Andrew Dunn
> Sent: Monday, July 30, 2007 12:31
> To: [email protected]
> Subject: Re: [DOTNET-WEB] Bitmap .net GDI+
>
> Hi,
>
> Thank you. This has given me a few ideas.
>
> One idea I was thinking of was rather than returning a bitmap
> was returning a string with a location to the bitmap (on
> disk) and the calling class can then do what it likes with
> it. Any thoughts on this?
>
> Andrew

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com