コード例 #1
0
 public void SaveStreamToJpeg(Stream sourceImage, string imageName)
 {
     try
     {
         RasterCodecs.Startup();
         rasterCodecs = new RasterCodecs();
         img          = rasterCodecs.Load(sourceImage);
         Leadtools.RasterImageFormat rif = Leadtools.RasterImageFormat.Jpeg;
         rasterCodecs.Save(img, imageName, rif, img.BitsPerPixel);
     }
     finally
     {
         img.Dispose();
         RasterCodecs.Shutdown();
     }
 }
コード例 #2
0
        private void Watermark()
        {
            int?left = null;
            int?top  = null;

            try
            {
                left = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='watermark']/left").InnerText.Trim());
                top  = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='watermark']/top").InnerText.Trim());
            }
            catch { }
            string watermarkFile = xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='watermark']/watermarkFile").InnerText.Trim();

            Leadtools.RasterImage watermark = rasterCodecs.Load(ApplicationPath + watermarkFile);
            Rectangle             destinationRectangle;

            if (left.HasValue && top.HasValue)
            {
                destinationRectangle = new Rectangle(left.Value, top.Value, watermark.Width, watermark.Height);
            }
            else
            {
                left = Math.Max(0, (img.Width - watermark.Width) / 2);
                top  = Math.Max(0, (img.Height - watermark.Height) / 2);
                destinationRectangle = new Rectangle(left.Value, top.Value, watermark.Width, watermark.Height);
            }

            // Jpg + png + png mask
            RasterImage watermarkMask        = watermark.CreateAlphaImage();
            FeatherAlphaBlendCommand command = new FeatherAlphaBlendCommand(watermark, new Point(0, 0), destinationRectangle, watermarkMask, new Point(0, 0));

            command.Run(img);

            // Jpg + jpg
            // CombineFastCommand combine = new CombineFastCommand();
            // combine.DestinationImage = img;
            // combine.DestinationRectangle = new Rectangle(left, top, watermark.Width, watermark.Height);
            // combine.SourcePoint = new Point(0, 0);
            // combine.Flags = CombineFastCommandFlags.SourceCopy;
            // combine.Run(watermark);

            watermark.Dispose();
        }
コード例 #3
0
        private string DoTheConvert(string sourceImage, string actionProfile, string annotate, ReturnPath retPath)
        {
            string strRetFile = "";

            strActionProfile = actionProfile;
            strAnnotate      = annotate;
            this.sourceImage = sourceImage;

            try
            {
                RasterCodecs.Startup();
                RasterSupport.Unlock(RasterSupportType.Pro, "LhwcFdF3jN");
                bool isLocked = RasterSupport.IsLocked(RasterSupportType.Pro);
                rasterCodecs = new RasterCodecs();
                imageInfo    = rasterCodecs.GetInformation(sourceImage, true);
                if (imageInfo.TotalPages > 0 && imageInfo.Format == Leadtools.RasterImageFormat.Gif)
                {
                    rasterCodecs.Options.Gif.Load.AnimationLoop    = imageInfo.Gif.AnimationLoop;
                    rasterCodecs.Options.Gif.Save.AnimationLoop    = imageInfo.Gif.AnimationLoop;
                    rasterCodecs.Options.Gif.Save.UseAnimationLoop = imageInfo.Gif.HasAnimationLoop;

                    if (imageInfo.Gif.HasAnimationBackground)
                    {
                        rasterCodecs.Options.Gif.Save.AnimationBackground = imageInfo.Gif.AnimationBackground;
                    }
                    rasterCodecs.Options.Gif.Save.UseAnimationBackground = imageInfo.Gif.HasAnimationBackground;
                    // #1.0.5.0

                    if (imageInfo.Gif.HasAnimationPalette)
                    {
                        rasterCodecs.Options.Gif.Save.SetAnimationPalette(imageInfo.Gif.GetAnimationPalette());
                    }
                    rasterCodecs.Options.Gif.Save.UseAnimationPalette = imageInfo.Gif.HasAnimationPalette;

                    rasterCodecs.Options.Gif.Save.AnimationWidth  = imageInfo.Gif.AnimationWidth;
                    rasterCodecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight;
                }
                img = rasterCodecs.Load(sourceImage);

                // Load convert action profile
                if (Init(sourceImage, strActionProfile))
                {
                    // loop on actions
                    LoopActions();
                    SaveImage();

                    // add a copyright or something like this to the image
                    if (xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='annotate']") != null && strTargetImage.Length > 0)
                    {
                        Annotate();
                    }

                    if (retPath == ReturnPath.AbsPath)
                    {
                        strRetFile = strTargetImage;
                    }
                    else if (retPath == ReturnPath.Url)
                    {
                        strRetFile = strTargetImageUrl;
                    }
                }
            }

            finally
            {
                img.Dispose();
                RasterCodecs.Shutdown();
            }

            return(strRetFile);
        }
コード例 #4
0
 public ImageItem(Leadtools.RasterImage rasterImage, ImageCollection parent)
 {
     _rasterImage = rasterImage;
     _tag         = null;
     _parent      = parent;
 }
コード例 #5
0
 public ImageItem(Leadtools.RasterImage rasterImage, ImageCollection parent, object tag)
 {
     _rasterImage = rasterImage;
     _tag         = tag;
     _parent      = parent;
 }