/// <summary>
        /// Ignores modifyLayer - not supported by this renderer.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="textLayers"></param>
        /// <param name="showLayerCallback"></param>
        /// <param name="modifyLayer"></param>
        /// <returns></returns>
        public System.Drawing.Bitmap Render(Stream s, out IList<IPsdLayer> layers, RenderLayerDelegate showLayerCallback, ModifyLayerDelegate modifyLayer)
        {
            // Create the resultBitmap object which contains merged bitmap, 
            // and the currentBitmap object which contains current bitmap during iteration. 
            // These object enable you to operate with layers.
            Aurigma.GraphicsMill.Bitmap resultBitmap = new Aurigma.GraphicsMill.Bitmap();
            using (Aurigma.GraphicsMill.Bitmap currentBitmap = new Aurigma.GraphicsMill.Bitmap())
            {
                // Create advanced PSD reader object to read .psd files.
                using (Aurigma.GraphicsMill.Codecs.AdvancedPsdReader psdReader = new Aurigma.GraphicsMill.Codecs.AdvancedPsdReader(s))
                {

                    // Load the background layer which you will put other layers on. 
                    // Remember that the layer on zero position should be skiped 
                    // because it contains merged bitmap.
                    Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame frame;
                    using (frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(1))
                    {
                        frame.GetBitmap(resultBitmap);
                    }

                    //List of layers
                    layers = new List<IPsdLayer>();

                    //This code merges the rest layers with the background layer one by one.
                    for (int i = 2; i < psdReader.FrameCount; i++)
                    {
                        using (frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(i))
                        {

                            // Do not forget to verify the unknown layer type.  
                            if (frame.Type != Aurigma.GraphicsMill.Codecs.PsdFrameType.Unknown)
                            {
                                //Add layers
                                layers.Add(new PsdLayer(frame, i + 1));

                                bool showFrame = showLayerCallback(i - 1, frame.Name, frame.Visible); //Subtract 1 from index so layer 0 is the background layer
                                if (showFrame)
                                {
                                    // Extract the current image from the layer.
                                    frame.GetBitmap(currentBitmap);
                                   
                                    // Draw current layer on the result bitmap. 
                                    // Also check out if the layer is visible or not.
                                    // If the layer is invisible we skip it.
                                    currentBitmap.Draw(currentBitmap, frame.Left, frame.Top, frame.Width, frame.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 1, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality);
                                    
                                   
                                }
                            }
                        }
                    }
                }
            }
            return resultBitmap.ToGdiplusBitmapDirectly();
        }
Example #2
0
 /// <summary>
 /// Creates result image for image list - image of specified size, color and blended with background and foreground images.
 /// </summary>
 /// <param name="size">Desired size of the result image.</param>
 /// <param name="bkColor">Background color.</param>
 /// <param name="backImage">Background image.</param>
 /// <param name="foreImage">Foreground image.</param>
 /// <param name="image">Source image.</param>
 /// <param name="imgResult">Reference to a variable where to store result.</param>
 public static void CreateListImage(System.Drawing.Size size, System.Drawing.Color bkColor, Aurigma.GraphicsMill.Bitmap backImage, Aurigma.GraphicsMill.Bitmap foreImage, Aurigma.GraphicsMill.Bitmap image, out Aurigma.GraphicsMill.Bitmap imgResult)
 {
     imgResult = null;
     Aurigma.GraphicsMill.Bitmap newImage = new Aurigma.GraphicsMill.Bitmap(size.Width, size.Height, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb, bkColor);
     if (backImage != null)
     {
         newImage.Draw(
             backImage,
             (size.Width - backImage.Width) / 2,
             (size.Height - backImage.Height) / 2,
             backImage.Width,
             backImage.Height,
             Aurigma.GraphicsMill.Transforms.CombineMode.Alpha,
             1,
             Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.Medium);
     }
     if (image != null)
     {
         newImage.Draw(
             image,
             (size.Width - image.Width) / 2,
             (size.Height - image.Height) / 2,
             image.Width,
             image.Height,
             Aurigma.GraphicsMill.Transforms.CombineMode.Alpha,
             1,
             Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.Medium);
     }
     if (foreImage != null)
     {
         newImage.Draw(
             foreImage,
             (size.Width - foreImage.Width) / 2,
             (size.Height - foreImage.Height) / 2,
             foreImage.Width,
             foreImage.Height,
             Aurigma.GraphicsMill.Transforms.CombineMode.Alpha,
             0.5f,
             Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.Medium);
     }
     imgResult = newImage;
 }
Example #3
0
        /// <summary>
        /// A part of the cached image lying inside the specified rectangle is draw on the given bitmap.
        /// No drawing is performed unless the cache is actual for the specified zoom.
        /// </summary>
        /// <returns>Return part of the rect that had been drawn from the cache (in viewportOrigin coordinates).</returns>
        public System.Drawing.Rectangle DrawCached(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            if (!HasActualData(zoom, renderingRegion))
            {
                return(System.Drawing.Rectangle.Empty);
            }

            System.Drawing.Rectangle intersection = System.Drawing.Rectangle.Intersect(renderingRegion, _viewport),
                                     dstRect      = intersection,
                                     srcRect      = intersection;

            srcRect.Offset(-_viewport.X, -_viewport.Y);
            dstRect.Offset(-viewport.X, -viewport.Y);

            using (var ct = new Aurigma.GraphicsMill.Transforms.Crop(srcRect))
                using (var cropResult = ct.Apply(_image))
                {
                    canvas.Draw(cropResult, dstRect.Left, dstRect.Top, Aurigma.GraphicsMill.Transforms.CombineMode.Copy);
                }

            return(intersection);
        }
Example #4
0
        /// <summary>
        /// Ignores modifyLayer - not supported by this renderer.
        /// </summary>
        /// <param name="s"></param>
        /// <param name="textLayers"></param>
        /// <param name="showLayerCallback"></param>
        /// <param name="modifyLayer"></param>
        /// <returns></returns>
        public System.Drawing.Bitmap Render(Stream s, out IList<IPsdLayer> layers, RenderLayerDelegate showLayerCallback, ModifyLayerDelegate modifyLayer)
        {
            // Create the resultBitmap object which contains merged bitmap,
            // and the currentBitmap object which contains current bitmap during iteration.
            // These object enable you to operate with layers.
            Aurigma.GraphicsMill.Bitmap resultBitmap = new Aurigma.GraphicsMill.Bitmap();
            using (Aurigma.GraphicsMill.Bitmap currentBitmap = new Aurigma.GraphicsMill.Bitmap())
            {
                // Create advanced PSD reader object to read .psd files.
                using (Aurigma.GraphicsMill.Codecs.AdvancedPsdReader psdReader = new Aurigma.GraphicsMill.Codecs.AdvancedPsdReader(s))
                {

                    // Load the background layer which you will put other layers on.
                    // Remember that the layer on zero position should be skiped
                    // because it contains merged bitmap.
                    Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame frame;
                    using (frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(1))
                    {
                        frame.GetBitmap(resultBitmap);
                    }

                    //List of layers
                    layers = new List<IPsdLayer>();

                    //This code merges the rest layers with the background layer one by one.
                    for (int i = 2; i < psdReader.FrameCount; i++)
                    {
                        using (frame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(i))
                        {

                            // Do not forget to verify the unknown layer type.
                            if (frame.Type != Aurigma.GraphicsMill.Codecs.PsdFrameType.Unknown)
                            {
                                //Add layers
                                layers.Add(new PsdLayer(frame, i + 1));

                                bool showFrame = showLayerCallback(i - 1, frame.Name, frame.Visible); //Subtract 1 from index so layer 0 is the background layer
                                if (showFrame)
                                {
                                    // Extract the current image from the layer.
                                    frame.GetBitmap(currentBitmap);

                                    // Draw current layer on the result bitmap.
                                    // Also check out if the layer is visible or not.
                                    // If the layer is invisible we skip it.
                                    currentBitmap.Draw(currentBitmap, frame.Left, frame.Top, frame.Width, frame.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 1, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality);

                                }
                            }
                        }
                    }
                }
            }
            return resultBitmap.ToGdiplusBitmapDirectly();
        }
Example #5
0
        protected override int _AddImageInternal(Aurigma.GraphicsMill.Bitmap image, int destinationIndex)
        {
            if (image == null)
            {
                return(-1);
            }

            int result = -1;

            lock (this)
            {
                if (_imageList == null)
                {
                    throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("InternalImageListCannotBeNull"));
                }

                bool disposeImage = false;
                if (_imageList.ImageSize.Width != image.Width || _imageList.ImageSize.Height != image.Height)
                {
                    Aurigma.GraphicsMill.Bitmap imageCopy = ConvertToNonextendedRgb(image);
                    if (imageCopy == image)
                    {
                        imageCopy = new Aurigma.GraphicsMill.Bitmap(image);
                    }

                    imageCopy.Transforms.Resize(_imageList.ImageSize.Width, _imageList.ImageSize.Height, Transforms.ResizeInterpolationMode.High, Transforms.ResizeMode.Shrink);

                    int destX = (_imageList.ImageSize.Width - imageCopy.Width) / 2,
                        destY = (_imageList.ImageSize.Height - imageCopy.Height) / 2;

                    Aurigma.GraphicsMill.Bitmap resultImage = new Aurigma.GraphicsMill.Bitmap(
                        _imageList.ImageSize.Width,
                        _imageList.ImageSize.Height,
                        Aurigma.GraphicsMill.PixelFormat.Format32bppArgb,
                        new Aurigma.GraphicsMill.RgbColor(0xff, 0xff, 0xff, 0x0));

                    resultImage.Draw(imageCopy, destX, destY, image.Width, image.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Copy, Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.Low);
                    imageCopy.Dispose();

                    image        = resultImage;
                    disposeImage = true;
                }

                if (destinationIndex != -1)
                {
                    _imageList.Images[destinationIndex] = image.ToGdiPlusBitmap();
                    result = destinationIndex;
                }
                else
                {
                    _imageList.Images.Add(image.ToGdiPlusBitmap());
                    result = _imageList.Images.Count - 1;
                }

                if (disposeImage)
                {
                    image.Dispose();
                }
            }

            return(result);
        }