unknown
2004-11-10 13:50:25 UTC
Hi All,
I am getting an out of memory exception error calling Graphics.DrawImage on
a 12 Mb file in an ASP.NET app.
I am croping and resizing using the function (below)
My machine is a new and fast hyperthreaded pent 4, 1Gb ram, this should
work?
I can open the file in paint and view it in the windows previewer without a
problem.
The Jpeg file is created by converting a PDF to Jpeg using ghostscript at
600 DPI.
If I RIP the file at 300 DPI, obviously a smaller JPeg is created, which
works fine.
Any ideas would be greatly appreciated.
Thanks,
Mark
public static Image Crop(Image sourceImage, int x, int y, int width, int
height, int targetWidth, int targetHeight)
{
Bitmap bmpSource = new Bitmap(targetWidth, targetHeight,
PixelFormat.Format32bppArgb);
bmpSource.SetResolution(72, 72);
Graphics gdiSource = Graphics.FromImage(bmpSource);
try
{
gdiSource.InterpolationMode = InterpolationMode.HighQualityBicubic;
gdiSource.DrawImage(sourceImage,
new Rectangle(0, 0, targetWidth, targetHeight), // Resulting cropped image
size
new Rectangle(x, y, width, height), // Selected part of source image
GraphicsUnit.Pixel);
}
finally
{
gdiSource.Dispose();
}
return bmpSource;
}
I am getting an out of memory exception error calling Graphics.DrawImage on
a 12 Mb file in an ASP.NET app.
I am croping and resizing using the function (below)
My machine is a new and fast hyperthreaded pent 4, 1Gb ram, this should
work?
I can open the file in paint and view it in the windows previewer without a
problem.
The Jpeg file is created by converting a PDF to Jpeg using ghostscript at
600 DPI.
If I RIP the file at 300 DPI, obviously a smaller JPeg is created, which
works fine.
Any ideas would be greatly appreciated.
Thanks,
Mark
public static Image Crop(Image sourceImage, int x, int y, int width, int
height, int targetWidth, int targetHeight)
{
Bitmap bmpSource = new Bitmap(targetWidth, targetHeight,
PixelFormat.Format32bppArgb);
bmpSource.SetResolution(72, 72);
Graphics gdiSource = Graphics.FromImage(bmpSource);
try
{
gdiSource.InterpolationMode = InterpolationMode.HighQualityBicubic;
gdiSource.DrawImage(sourceImage,
new Rectangle(0, 0, targetWidth, targetHeight), // Resulting cropped image
size
new Rectangle(x, y, width, height), // Selected part of source image
GraphicsUnit.Pixel);
}
finally
{
gdiSource.Dispose();
}
return bmpSource;
}