Re: 'Out of Memory' exception when trying to Clone a Bitmap
- From: RichardB <RichardB@xxxxxxxxxxxxxxxxx>
- Date: Thu, 18 May 2006 07:35:02 -0700
Michael,
This sounds like an interesting alternative. Do you know hoe I would go
about this in .Net 1.1
I'm assuming the DrawImage method you are talking about is the GDI+ method
and not the .Net method.
Is there anything in the .Net framework, maybe in the Bitmap class, that
will do similar?
Sorry for my ignorance but I know little about ther GDI world. All I'm
looking to do is simply copy and crop a bitmap image. I was hoping the .Net
Bitmap.Clone method would perform this for me.
Thanks
--
Richard
"Michael Phillips, Jr." wrote:
There appears to be a memory allocation problem..
Gdiplus will only allocate memory when the image is actually accessed.
Since you are using a third party sdk, it seems that when gdiplus attempts
to access the image to intialize and allocate internal memory, there is a
failure.
No problem! You can safely create a new image with the bounds that you need
and use DrawImage to copy that portion of the original image to your new
image.
That is what I do in my own code to crop an image.
You must not use an indexed pixel format for the source and destination
image, as gdiplus cannot create a Graphics object from indexed images.
For indexed pixel formatted images, you must roll your own cropping by using
LockBits to access the internal bits of the image.
"RichardB" <RichardB@xxxxxxxxxxxxxxxxx> wrote in message
news:A0E2BF1C-FEE5-4D04-9216-EE805F136865@xxxxxxxxxxxxxxxx
Michael,
Thank you for the reply.
Firstly I have tried using regular and floating point bounds, both give
the
same problem.
Secondly the bounds are within the bounds of the first bitmap.
If I clone using the EXACT bounds of the original bitmap it works fine.
If I clone using anything smaller then it fails. I have tried using the
original bounds and just subtracting 1 from the height or width. It fails.
Could it be to do with something about the bitmap in question?
If I use my own bitmap, for example....
Bitmap MyBitmap = new Bitmap("filename.jpg");
.. then it works fine using smaller bounds for the clone.
If I use the one passed to me from the SDK then I can only copy it using
the
exact bounds. I need to copy and select a small part of the original.
Any ideas?
Thanks
--
Richard
"Michael Phillips, Jr." wrote:
Per the documentation, you only get that error when the bounding
rectangle
is outside of the source bitmap's bounds!
Did you check the bounds of the bitmap first. Additionally, you are
using a
bounding rectangle described with floating point bounds. Try a regular
Rectangle.
"RichardB" <RichardB@xxxxxxxxxxxxxxxxx> wrote in message
news:FC603D6E-0E98-437E-AF15-432BD96F1ABA@xxxxxxxxxxxxxxxx
I'm getting an 'Out of Memory' exception when I try to clone a Bitmap
object
in .Net 1.1
If I load a new bitmap (from a file for example) and clone it, it works
fine.
However I am getting a bitmap passed to me from an external 3rd party
SDK.
It's a C++ SDK with a .Net interop dll, so it should work fine.
If I clone the image as is (a straight full clone) then it's fine.
If however I clone the image and specify a reduced area to clone (as
per
the
.net Bitmap.Clone method) then it fails with 'Out of Memory error.
For example:
RectangleF NewRect = new RectangleF(0,0,10,10);
Bitmap Bitmap2 = Bitmap1.Clone(NewRect, Bitmap1.PixelFormat);
This fails on the second line.
Does anyone have any ideas?
Thank you
--
Richard
- Follow-Ups:
- Re: 'Out of Memory' exception when trying to Clone a Bitmap
- From: Michael Phillips, Jr.
- Re: 'Out of Memory' exception when trying to Clone a Bitmap
- References:
- Re: 'Out of Memory' exception when trying to Clone a Bitmap
- From: Michael Phillips, Jr.
- Re: 'Out of Memory' exception when trying to Clone a Bitmap
- From: RichardB
- Re: 'Out of Memory' exception when trying to Clone a Bitmap
- From: Michael Phillips, Jr.
- Re: 'Out of Memory' exception when trying to Clone a Bitmap
- Prev by Date: Re: Can one create WMF files with preset horiz and vert resolution?
- Next by Date: Re: 'Out of Memory' exception when trying to Clone a Bitmap
- Previous by thread: Re: 'Out of Memory' exception when trying to Clone a Bitmap
- Next by thread: Re: 'Out of Memory' exception when trying to Clone a Bitmap
- Index(es):
Relevant Pages
|