public void Decode_jp2k(string filename, string decodeType, Asset asset) { var img = (AssetTexture)asset; OpenMetaverse.Imaging.ManagedImage imgImage = img.Image; if (imgImage == null) { OpenJPEG.DecodeToImage(asset.AssetData, out imgImage); } if (imgImage != null) { if (filename.ToLower().EndsWith("tga")) { File.WriteAllBytes(filename, imgImage.ExportTGA()); } else { File.WriteAllBytes(filename, imgImage.ExportRaw()); } } }
/// <summary> /// Decode JPEG2000 data to an <seealso cref="System.Drawing.Image"/> and /// <seealso cref="ManagedImage"/> /// </summary> /// <param name="encoded">JPEG2000 encoded data</param> /// <param name="managedImage">ManagedImage object to decode to</param> /// <param name="image">Image object to decode to</param> /// <returns>True if the decode succeeds, otherwise false</returns> public static bool DecodeToImage(byte[] encoded, out ManagedImage managedImage, out Image image) { managedImage = null; image = null; if (DecodeToImage(encoded, out managedImage)) { try { image = LoadTGAClass.LoadTGA(new MemoryStream(managedImage.ExportTGA())); return(true); } catch (Exception ex) { Logger.Log("Failed to export and load TGA data from decoded image", Helpers.LogLevel.Error, ex); return(false); } } else { return(false); } }
/// <summary> /// Decode JPEG2000 data to an <seealso cref="System.Drawing.Image"/> and /// <seealso cref="ManagedImage"/> /// </summary> /// <param name="encoded">JPEG2000 encoded data</param> /// <param name="managedImage">ManagedImage object to decode to</param> /// <param name="image">Image object to decode to</param> /// <returns>True if the decode succeeds, otherwise false</returns> public static bool DecodeToImage(byte[] encoded, out ManagedImage managedImage, out Image image) { managedImage = null; image = null; if (DecodeToImage(encoded, out managedImage)) { try { image = LoadTGAClass.LoadTGA(new MemoryStream(managedImage.ExportTGA())); return true; } catch (Exception ex) { Logger.Log("Failed to export and load TGA data from decoded image", Helpers.LogLevel.Error, ex); return false; } } else { return false; } }