aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs')
-rw-r--r--OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs35
1 files changed, 19 insertions, 16 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
index ac99692..8215124 100644
--- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
+++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs
@@ -354,9 +354,9 @@ namespace OpenSim.Capabilities.Handlers
354 byte[] data = new byte[0]; 354 byte[] data = new byte[0];
355 355
356 MemoryStream imgstream = new MemoryStream(); 356 MemoryStream imgstream = new MemoryStream();
357 Bitmap mTexture = new Bitmap(1, 1); 357 Bitmap mTexture = null;
358 ManagedImage managedImage; 358 ManagedImage managedImage = null;
359 Image image = (Image)mTexture; 359 Image image = null;
360 360
361 try 361 try
362 { 362 {
@@ -365,25 +365,26 @@ namespace OpenSim.Capabilities.Handlers
365 imgstream = new MemoryStream(); 365 imgstream = new MemoryStream();
366 366
367 // Decode image to System.Drawing.Image 367 // Decode image to System.Drawing.Image
368 if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image)) 368 if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image) && image != null)
369 { 369 {
370 // Save to bitmap 370 // Save to bitmap
371 mTexture = new Bitmap(image); 371 mTexture = new Bitmap(image);
372 372
373 EncoderParameters myEncoderParameters = new EncoderParameters(); 373 using(EncoderParameters myEncoderParameters = new EncoderParameters())
374 myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 95L);
375
376 // Save bitmap to stream
377 ImageCodecInfo codec = GetEncoderInfo("image/" + format);
378 if (codec != null)
379 { 374 {
380 mTexture.Save(imgstream, codec, myEncoderParameters); 375 myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality,95L);
376
377 // Save bitmap to stream
378 ImageCodecInfo codec = GetEncoderInfo("image/" + format);
379 if (codec != null)
380 {
381 mTexture.Save(imgstream, codec, myEncoderParameters);
381 // Write the stream to a byte array for output 382 // Write the stream to a byte array for output
382 data = imgstream.ToArray(); 383 data = imgstream.ToArray();
384 }
385 else
386 m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format);
383 } 387 }
384 else
385 m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format);
386
387 } 388 }
388 } 389 }
389 catch (Exception e) 390 catch (Exception e)
@@ -399,7 +400,9 @@ namespace OpenSim.Capabilities.Handlers
399 400
400 if (image != null) 401 if (image != null)
401 image.Dispose(); 402 image.Dispose();
402 403
404 if(managedImage != null)
405 managedImage.Clear();
403 if (imgstream != null) 406 if (imgstream != null)
404 { 407 {
405 imgstream.Close(); 408 imgstream.Close();