aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs59
1 files changed, 37 insertions, 22 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
index 3921bf9..039c3fa 100644
--- a/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
+++ b/OpenSim/Region/CoreModules/World/Terrain/FileLoaders/GenericSystemDrawing.cs
@@ -138,35 +138,50 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
138 // "Saving the image to the same file it was constructed from is not allowed and throws an exception." 138 // "Saving the image to the same file it was constructed from is not allowed and throws an exception."
139 string tempName = Path.GetTempFileName(); 139 string tempName = Path.GetTempFileName();
140 140
141 Bitmap entireBitmap = null; 141 Bitmap existingBitmap = null;
142 Bitmap thisBitmap = null; 142 Bitmap thisBitmap;
143 if (File.Exists(filename)) 143 Bitmap newBitmap;
144
145 try
144 { 146 {
145 File.Copy(filename, tempName, true); 147 if (File.Exists(filename))
146 entireBitmap = new Bitmap(tempName);
147 if (entireBitmap.Width != fileWidth * regionSizeX || entireBitmap.Height != fileHeight * regionSizeY)
148 { 148 {
149 // old file, let's overwrite it 149 File.Copy(filename, tempName, true);
150 entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); 150 existingBitmap = new Bitmap(tempName);
151 if (existingBitmap.Width != fileWidth * regionSizeX || existingBitmap.Height != fileHeight * regionSizeY)
152 {
153 // old file, let's overwrite it
154 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
155 }
156 else
157 {
158 newBitmap = existingBitmap;
159 }
151 } 160 }
161 else
162 {
163 newBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY);
164 }
165
166 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
167 // Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
168 for (int x = 0; x < regionSizeX; x++)
169 for (int y = 0; y < regionSizeY; y++)
170 newBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
171
172 Save(newBitmap, filename);
152 } 173 }
153 else 174 finally
154 { 175 {
155 entireBitmap = new Bitmap(fileWidth * regionSizeX, fileHeight * regionSizeY); 176 if (existingBitmap != null)
156 } 177 existingBitmap.Dispose();
157
158 thisBitmap = CreateGrayscaleBitmapFromMap(m_channel);
159// Console.WriteLine("offsetX=" + offsetX + " offsetY=" + offsetY);
160 for (int x = 0; x < regionSizeX; x++)
161 for (int y = 0; y < regionSizeY; y++)
162 entireBitmap.SetPixel(x + offsetX * regionSizeX, y + (fileHeight - 1 - offsetY) * regionSizeY, thisBitmap.GetPixel(x, y));
163 178
164 Save(entireBitmap, filename); 179 thisBitmap.Dispose();
165 thisBitmap.Dispose(); 180 newBitmap.Dispose();
166 entireBitmap.Dispose();
167 181
168 if (File.Exists(tempName)) 182 if (File.Exists(tempName))
169 File.Delete(tempName); 183 File.Delete(tempName);
184 }
170 } 185 }
171 186
172 protected virtual void Save(Bitmap bmp, string filename) 187 protected virtual void Save(Bitmap bmp, string filename)