By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,969 Members | 2,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,969 IT Pros & Developers. It's quick & easy.

Huge image resize

P: n/a
I have huge bitmap inmemory (about 4K x 6K 300dpi) and I want to quick
resize it so old fasion way:
Bitmap result = new Bitmap( nSize.Width, nSize.Height);
using(
Graphics g1 = Graphics.FromImage( (Image) result ) )
{
g1.DrawImage( b, 0, 0, nSize.Width, nSize.Height );
}

working rather fine the first (and even second time), but each time it used
the process takes x2 time (no difference between make the bitmap bigger or
smaller)
so the fifth time application crashed with no memory

Anyone can advice WHY and maybe better way to do this. I have concurrent one
image in application.

I do not want to go unmanaged this time.

thx

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Tamir,

Are you disposing of the Bitmap image correctly? You should be calling
Dispose on the images when done. Images of that size take quite a bit of
memory, and not disposing of them could cause performance degredation pretty
quickly.

Also, are you using them just as-needed, or caching them in memory? You
might want to reconsider caching them in memory if this is the case.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:Or*************@TK2MSFTNGP12.phx.gbl...
I have huge bitmap inmemory (about 4K x 6K 300dpi) and I want to quick
resize it so old fasion way:
Bitmap result = new Bitmap( nSize.Width, nSize.Height);
using(
Graphics g1 = Graphics.FromImage( (Image) result ) )
{
g1.DrawImage( b, 0, 0, nSize.Width, nSize.Height );
}

working rather fine the first (and even second time), but each time it
used the process takes x2 time (no difference between make the bitmap
bigger or smaller)
so the fifth time application crashed with no memory

Anyone can advice WHY and maybe better way to do this. I have concurrent
one image in application.

I do not want to go unmanaged this time.

thx

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nov 16 '05 #2

P: n/a
Hi, Nicholas and thank you for response,
as you can see I'm using following method for disposing:
using(
Graphics g1 = Graphics.FromImage( (Image) result ) )
because if I'll dispose the graphics before return the resized image will be
lost.
How can I cache the image within C#? are there any methods you know to do
this?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OY*************@TK2MSFTNGP14.phx.gbl...
Tamir,

Are you disposing of the Bitmap image correctly? You should be calling
Dispose on the images when done. Images of that size take quite a bit of
memory, and not disposing of them could cause performance degredation
pretty quickly.

Also, are you using them just as-needed, or caching them in memory?
You might want to reconsider caching them in memory if this is the case.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:Or*************@TK2MSFTNGP12.phx.gbl...
I have huge bitmap inmemory (about 4K x 6K 300dpi) and I want to quick
resize it so old fasion way:
Bitmap result = new Bitmap( nSize.Width, nSize.Height);
using(
Graphics g1 = Graphics.FromImage( (Image) result ) )
{
g1.DrawImage( b, 0, 0, nSize.Width, nSize.Height );
}

working rather fine the first (and even second time), but each time it
used the process takes x2 time (no difference between make the bitmap
bigger or smaller)
so the fifth time application crashed with no memory

Anyone can advice WHY and maybe better way to do this. I have concurrent
one image in application.

I do not want to go unmanaged this time.

thx

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "


Nov 16 '05 #3

P: n/a
Tamir,

You are disposing of the Graphics context, but you are not disposing of
the image. When you are done with it, are you disposing of it? How are you
using it (the Bitmap variable).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:eQ**************@TK2MSFTNGP12.phx.gbl...
Hi, Nicholas and thank you for response,
as you can see I'm using following method for disposing:
using(
Graphics g1 = Graphics.FromImage( (Image) result ) )
because if I'll dispose the graphics before return the resized image will
be lost.
How can I cache the image within C#? are there any methods you know to do
this?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:OY*************@TK2MSFTNGP14.phx.gbl...
Tamir,

Are you disposing of the Bitmap image correctly? You should be
calling Dispose on the images when done. Images of that size take quite
a bit of memory, and not disposing of them could cause performance
degredation pretty quickly.

Also, are you using them just as-needed, or caching them in memory?
You might want to reconsider caching them in memory if this is the case.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:Or*************@TK2MSFTNGP12.phx.gbl...
I have huge bitmap inmemory (about 4K x 6K 300dpi) and I want to quick
resize it so old fasion way:
Bitmap result = new Bitmap( nSize.Width, nSize.Height);
using(
Graphics g1 = Graphics.FromImage( (Image) result ) )
{
g1.DrawImage( b, 0, 0, nSize.Width, nSize.Height );
}

working rather fine the first (and even second time), but each time it
used the process takes x2 time (no difference between make the bitmap
bigger or smaller)
so the fifth time application crashed with no memory

Anyone can advice WHY and maybe better way to do this. I have concurrent
one image in application.

I do not want to go unmanaged this time.

thx

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "



Nov 16 '05 #4

P: n/a

Bitmap m_bitmap;
//Loaded
m_bitmap = ResizeBitmap(m_bitmap,myNewSize);
it should be reused, no?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O2*************@tk2msftngp13.phx.gbl...
Tamir,

You are disposing of the Graphics context, but you are not disposing of
the image. When you are done with it, are you disposing of it? How are
you using it (the Bitmap variable).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:eQ**************@TK2MSFTNGP12.phx.gbl...
Hi, Nicholas and thank you for response,
as you can see I'm using following method for disposing:
using(
Graphics g1 = Graphics.FromImage( (Image) result ) )
because if I'll dispose the graphics before return the resized image will
be lost.
How can I cache the image within C#? are there any methods you know to do
this?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:OY*************@TK2MSFTNGP14.phx.gbl...
Tamir,

Are you disposing of the Bitmap image correctly? You should be
calling Dispose on the images when done. Images of that size take quite
a bit of memory, and not disposing of them could cause performance
degredation pretty quickly.

Also, are you using them just as-needed, or caching them in memory?
You might want to reconsider caching them in memory if this is the case.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:Or*************@TK2MSFTNGP12.phx.gbl...
I have huge bitmap inmemory (about 4K x 6K 300dpi) and I want to quick
resize it so old fasion way:
Bitmap result = new Bitmap( nSize.Width, nSize.Height);
using(
Graphics g1 = Graphics.FromImage( (Image) result ) )
{
g1.DrawImage( b, 0, 0, nSize.Width, nSize.Height );
}

working rather fine the first (and even second time), but each time it
used the process takes x2 time (no difference between make the bitmap
bigger or smaller)
so the fifth time application crashed with no memory

Anyone can advice WHY and maybe better way to do this. I have
concurrent one image in application.

I do not want to go unmanaged this time.

thx

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "



Nov 16 '05 #5

P: n/a
Tamir,

I'm going to assumpe that m_bitmap is a field in a class. Does this
class implement IDisposable? If so, is it being called correctly when done?
The bitmap is never being GCed as soon as it can be if it is not being
disposed (not to mention the unmanaged resources that are waiting to be
disposed of).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:e$**************@TK2MSFTNGP15.phx.gbl...

Bitmap m_bitmap;
//Loaded
m_bitmap = ResizeBitmap(m_bitmap,myNewSize);
it should be reused, no?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:O2*************@tk2msftngp13.phx.gbl...
Tamir,

You are disposing of the Graphics context, but you are not disposing
of the image. When you are done with it, are you disposing of it? How
are you using it (the Bitmap variable).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:eQ**************@TK2MSFTNGP12.phx.gbl...
Hi, Nicholas and thank you for response,
as you can see I'm using following method for disposing:
using(
Graphics g1 = Graphics.FromImage( (Image) result ) )
because if I'll dispose the graphics before return the resized image
will be lost.
How can I cache the image within C#? are there any methods you know to
do this?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:OY*************@TK2MSFTNGP14.phx.gbl...
Tamir,

Are you disposing of the Bitmap image correctly? You should be
calling Dispose on the images when done. Images of that size take
quite a bit of memory, and not disposing of them could cause
performance degredation pretty quickly.

Also, are you using them just as-needed, or caching them in memory?
You might want to reconsider caching them in memory if this is the
case.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:Or*************@TK2MSFTNGP12.phx.gbl...
>I have huge bitmap inmemory (about 4K x 6K 300dpi) and I want to quick
>resize it so old fasion way:
> Bitmap result = new Bitmap( nSize.Width, nSize.Height);
> using(
> Graphics g1 = Graphics.FromImage( (Image) result ) )
> {
> g1.DrawImage( b, 0, 0, nSize.Width, nSize.Height );
> }
>
> working rather fine the first (and even second time), but each time it
> used the process takes x2 time (no difference between make the bitmap
> bigger or smaller)
> so the fifth time application crashed with no memory
>
> Anyone can advice WHY and maybe better way to do this. I have
> concurrent one image in application.
>
> I do not want to go unmanaged this time.
>
> thx
>
> --
> Tamir Khason
> You want dot.NET? Just ask:
> "Please, www.dotnet.us "
>
>



Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.