Exemplo n.º 1
0
        public static void SaveImage(Stream stream, FreeImageBitmap bitmap)
        {
            AjpHeader ajpHeaderFromBitmap  = bitmap.Tag as AjpHeader;
            AjpHeader ajpHeaderFromComment = null;

            if (!string.IsNullOrEmpty(bitmap.Comment))
            {
                ajpHeaderFromComment = new AjpHeader();
                if (!ajpHeaderFromComment.ParseComment(bitmap.Comment))
                {
                    ajpHeaderFromComment = null;
                }
            }

            var ms  = new MemoryStream();
            var ms2 = new MemoryStream();

            bitmap.Save(ms, FREE_IMAGE_FORMAT.FIF_JPEG, FREE_IMAGE_SAVE_FLAGS.JPEG_PROGRESSIVE | FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD);
            using (var alpha = bitmap.GetChannel(FREE_IMAGE_COLOR_CHANNEL.FICC_ALPHA))
            {
                if (alpha != null)
                {
                    alpha.Comment = "signature = 19792, version = 2, headerSize = 64, colorDepth = 8";
                    Pms.SaveImage(ms2, alpha);
                }
            }

            AjpHeader ajpHeader = ajpHeaderFromBitmap;

            if (ajpHeader == null)
            {
                ajpHeader = ajpHeaderFromComment;
            }
            SaveImage(stream, ms.ToArray(), ms2.ToArray(), ajpHeader);
        }
Exemplo n.º 2
0
        public static void SaveImage(Stream stream, byte[] jpegFile, FreeImageBitmap alpha, AjpHeader ajpHeader)
        {
            byte[] pmsFile = null;
            if (alpha != null)
            {
                using (var ms = new MemoryStream()) {
                    alpha.Comment = "signature = 19792, version = 2, headerSize = 64";
                    Pms.SaveImage(ms, alpha);
                    pmsFile = ms.ToArray();
                }
            }

            SaveImage(stream, jpegFile, pmsFile, ajpHeader);
        }