Always dispose of existing opened bitmap from file in SaveFile(), instead of simply dropping the reference if the existing file didn't contain a bitmap of the same size.
parent
cba64ebc79
commit
75f117484b
|
@ -138,35 +138,50 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||||
// "Saving the image to the same file it was constructed from is not allowed and throws an exception."
|
// "Saving the image to the same file it was constructed from is not allowed and throws an exception."
|
||||||
string tempName = Path.GetTempFileName();
|
string tempName = Path.GetTempFileName();
|
||||||
|
|
||||||
Bitmap entireBitmap = null;
|
Bitmap existingBitmap = null;
|
||||||
Bitmap thisBitmap = null;
|
Bitmap thisBitmap;
|
||||||
if (File.Exists(filename))
|
Bitmap newBitmap;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
File.Copy(filename, tempName, true);
|
if (File.Exists(filename))
|
||||||
entireBitmap = new Bitmap(tempName);
|
|
||||||
if (entireBitmap.Width != fileWidth * regionSizeX || entireBitmap.Height != fileHeight * regionSizeY)
|
|
||||||
{
|
{
|
||||||
// old file, let's overwrite it
|
File.Copy(filename, tempName, true);
|
||||||
entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
|
existingBitmap = new Bitmap(tempName);
|
||||||
|
if (existingBitmap.Width != fileWidth * regionSizeX || existingBitmap.Height != fileHeight * regionSizeY)
|
||||||
|
{
|
||||||
|
// old file, let's overwrite it
|
||||||
|
newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newBitmap = existingBitmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
|
||||||
|
}
|
||||||
|
|
||||||
|
thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
|
||||||
|
// Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
|
||||||
|
for (int x = 0; x < regionSizeX; x++)
|
||||||
|
for (int y = 0; y < regionSizeY; y++)
|
||||||
|
newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
|
||||||
|
|
||||||
|
Save(newBitmap, filename);
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
{
|
||||||
entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
|
if (existingBitmap != null)
|
||||||
|
existingBitmap.Dispose();
|
||||||
|
|
||||||
|
thisBitmap.Dispose();
|
||||||
|
newBitmap.Dispose();
|
||||||
|
|
||||||
|
if (File.Exists(tempName))
|
||||||
|
File.Delete(tempName);
|
||||||
}
|
}
|
||||||
|
|
||||||
thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
|
|
||||||
// Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
|
|
||||||
for (int x = 0; x < regionSizeX; x++)
|
|
||||||
for (int y = 0; y < regionSizeY; y++)
|
|
||||||
entireBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
|
|
||||||
|
|
||||||
Save(entireBitmap, filename);
|
|
||||||
thisBitmap.Dispose();
|
|
||||||
entireBitmap.Dispose();
|
|
||||||
|
|
||||||
if (File.Exists(tempName))
|
|
||||||
File.Delete(tempName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Save(Bitmap bmp, string filename)
|
protected virtual void Save(Bitmap bmp, string filename)
|
||||||
|
|
Loading…
Reference in New Issue