diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs index f813471..518f74e 100644 --- a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureRobustHandler.cs | |||
@@ -359,9 +359,9 @@ namespace OpenSim.Capabilities.Handlers | |||
359 | byte[] data = new byte[0]; | 359 | byte[] data = new byte[0]; |
360 | 360 | ||
361 | MemoryStream imgstream = new MemoryStream(); | 361 | MemoryStream imgstream = new MemoryStream(); |
362 | Bitmap mTexture = new Bitmap(1, 1); | 362 | Bitmap mTexture = null; |
363 | ManagedImage managedImage; | 363 | ManagedImage managedImage = null; |
364 | Image image = (Image)mTexture; | 364 | Image image = null; |
365 | 365 | ||
366 | try | 366 | try |
367 | { | 367 | { |
@@ -370,25 +370,26 @@ namespace OpenSim.Capabilities.Handlers | |||
370 | imgstream = new MemoryStream(); | 370 | imgstream = new MemoryStream(); |
371 | 371 | ||
372 | // Decode image to System.Drawing.Image | 372 | // Decode image to System.Drawing.Image |
373 | if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image)) | 373 | if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image) && image != null) |
374 | { | 374 | { |
375 | // Save to bitmap | 375 | // Save to bitmap |
376 | mTexture = new Bitmap(image); | 376 | mTexture = new Bitmap(image); |
377 | 377 | ||
378 | EncoderParameters myEncoderParameters = new EncoderParameters(); | 378 | using(EncoderParameters myEncoderParameters = new EncoderParameters()) |
379 | myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 95L); | ||
380 | |||
381 | // Save bitmap to stream | ||
382 | ImageCodecInfo codec = GetEncoderInfo("image/" + format); | ||
383 | if (codec != null) | ||
384 | { | 379 | { |
385 | mTexture.Save(imgstream, codec, myEncoderParameters); | 380 | myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality,95L); |
386 | // Write the stream to a byte array for output | ||
387 | data = imgstream.ToArray(); | ||
388 | } | ||
389 | else | ||
390 | m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format); | ||
391 | 381 | ||
382 | // Save bitmap to stream | ||
383 | ImageCodecInfo codec = GetEncoderInfo("image/" + format); | ||
384 | if (codec != null) | ||
385 | { | ||
386 | mTexture.Save(imgstream, codec, myEncoderParameters); | ||
387 | // Write the stream to a byte array for output | ||
388 | data = imgstream.ToArray(); | ||
389 | } | ||
390 | else | ||
391 | m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format); | ||
392 | } | ||
392 | } | 393 | } |
393 | } | 394 | } |
394 | catch (Exception e) | 395 | catch (Exception e) |
@@ -405,6 +406,9 @@ namespace OpenSim.Capabilities.Handlers | |||
405 | if (image != null) | 406 | if (image != null) |
406 | image.Dispose(); | 407 | image.Dispose(); |
407 | 408 | ||
409 | if(managedImage != null) | ||
410 | managedImage.Clear(); | ||
411 | |||
408 | if (imgstream != null) | 412 | if (imgstream != null) |
409 | { | 413 | { |
410 | imgstream.Close(); | 414 | imgstream.Close(); |