Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        public static ManagedImage LoadAlphaLayer(string fileName)
        {
            Stream stream = Helpers.GetResourceStream(fileName);

            if (stream != null)
            {
                try
                {
                    // FIXME: It would save cycles and memory if we wrote a direct
                    // loader to ManagedImage for these files instead of using the
                    // TGA loader
                    Bitmap bitmap = LoadTGAClass.LoadTGA(stream);
                    stream.Close();

                    ManagedImage alphaLayer = new ManagedImage(bitmap);

                    // Disable all layers except the alpha layer
                    alphaLayer.Red      = null;
                    alphaLayer.Green    = null;
                    alphaLayer.Blue     = null;
                    alphaLayer.Channels = ManagedImage.ImageChannels.Alpha;

                    return(alphaLayer);
                }
                catch (Exception e)
                {
                    Logger.Log(String.Format("LoadAlphaLayer() failed on file: {0} ({1}", fileName, e.Message),
                               Helpers.LogLevel.Error, e);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }