Explicitly dispose of bitmaps opened from files in GenericSystemDrawing and JPEG.cs

0.7.4.1
Justin Clark-Casey (justincc) 2012-04-20 03:46:09 +01:00
parent 4ac2f839bd
commit cba64ebc79
2 changed files with 31 additions and 18 deletions

View File

@ -59,7 +59,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <returns>A terrain channel generated from the image.</returns> /// <returns>A terrain channel generated from the image.</returns>
public virtual ITerrainChannel LoadFile(string filename) public virtual ITerrainChannel LoadFile(string filename)
{ {
return LoadBitmap(new Bitmap(filename)); using (Bitmap b = new Bitmap(filename))
return LoadBitmap(b);
} }
public virtual ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int w, int h) public virtual ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int w, int h)
@ -75,13 +76,15 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
retval[x, y] = bitmap.GetPixel(offsetX * retval.Width + x, (bitmap.Height - (retval.Height * (offsetY + 1))) + retval.Height - y - 1).GetBrightness() * 128; retval[x, y] = bitmap.GetPixel(offsetX * retval.Width + x, (bitmap.Height - (retval.Height * (offsetY + 1))) + retval.Height - y - 1).GetBrightness() * 128;
} }
} }
return retval; return retval;
} }
} }
public virtual ITerrainChannel LoadStream(Stream stream) public virtual ITerrainChannel LoadStream(Stream stream)
{ {
return LoadBitmap(new Bitmap(stream)); using (Bitmap b = new Bitmap(stream))
return LoadBitmap(b);
} }
protected virtual ITerrainChannel LoadBitmap(Bitmap bitmap) protected virtual ITerrainChannel LoadBitmap(Bitmap bitmap)
@ -227,16 +230,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
/// <returns>A System.Drawing.Bitmap containing a coloured image</returns> /// <returns>A System.Drawing.Bitmap containing a coloured image</returns>
protected static Bitmap CreateBitmapFromMap(ITerrainChannel map) protected static Bitmap CreateBitmapFromMap(ITerrainChannel map)
{ {
Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); int pallete;
Bitmap bmp;
Color[] colours;
int pallete = gradientmapLd.Height; using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png"))
Bitmap bmp = new Bitmap(map.Width, map.Height);
Color[] colours = new Color[pallete];
for (int i = 0; i < pallete; i++)
{ {
colours[i] = gradientmapLd.GetPixel(0, i); pallete = gradientmapLd.Height;
bmp = new Bitmap(map.Width, map.Height);
colours = new Color[pallete];
for (int i = 0; i < pallete; i++)
{
colours[i] = gradientmapLd.GetPixel(0, i);
}
} }
for (int y = 0; y < map.Height; y++) for (int y = 0; y < map.Height; y++)

View File

@ -99,16 +99,21 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
private static Bitmap CreateBitmapFromMap(ITerrainChannel map) private static Bitmap CreateBitmapFromMap(ITerrainChannel map)
{ {
Bitmap gradientmapLd = new Bitmap("defaultstripe.png"); int pallete;
Bitmap bmp;
Color[] colours;
int pallete = gradientmapLd.Height; using (Bitmap gradientmapLd = new Bitmap("defaultstripe.png"))
Bitmap bmp = new Bitmap(map.Width, map.Height);
Color[] colours = new Color[pallete];
for (int i = 0; i < pallete; i++)
{ {
colours[i] = gradientmapLd.GetPixel(0, i); pallete = gradientmapLd.Height;
bmp = new Bitmap(map.Width, map.Height);
colours = new Color[pallete];
for (int i = 0; i < pallete; i++)
{
colours[i] = gradientmapLd.GetPixel(0, i);
}
} }
for (int y = 0; y < map.Height; y++) for (int y = 0; y < map.Height; y++)