Ejemplo n.º 1
0
        public Bitmap Render(Stream s, out IList <IPsdLayer> layers, out Size size, ShowLayerDelegate showLayerCallback, ComposeLayerDelegate composeLayer)
        {
            PsdFile file = new PsdFile();

            file.Load(s);
            //Start with a transparent bitmap (not all PSD files have background layers)
            size = new Size(file.Columns, file.Rows);
            Bitmap b = new Bitmap(file.Columns, file.Rows);

            //ImageDecoder.DecodeImage(file.Layers[0]); //Layers collection doesn't include the composed layer

            Graphics g = Graphics.FromImage(b);

            using (g){
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.CompositingMode    = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                for (int i = 0; i < file.Layers.Count; i++)
                {
                    if (showLayerCallback(i, file.Layers[i].Name, file.Layers[i].Visible))
                    {
                        using (Bitmap frame = ImageDecoder.DecodeImage(file.Layers[i])){
                            composeLayer(g, frame, file.Layers[i]);
                        }
                    }
                }
            }
            layers = getLayers(file);
            return(b);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a collection of all visible text layers for the file (memcached). Useful for building image maps
        /// </summary>
        /// <param name="virtualPath"></param>
        /// <param name="queryString"></param>
        /// <returns></returns>
        public IList <IPsdLayer> GetVisibleTextLayers(string virtualPath, NameValueCollection queryString)
        {
            //Get all layers
            IList <IPsdLayer> layers = GetAllLayers(virtualPath, queryString);


            Stopwatch sw = new Stopwatch();

            sw.Start();
            //Now, time to filter layers to those that would be showing on the image right now.
            IList <IPsdLayer> filtered = new List <IPsdLayer>();

            //Generate a callback just like the one used in the renderer for filtering
            ShowLayerDelegate callback = BuildLayerCallback(queryString);

            for (int i = 0; i < layers.Count; i++)
            {
                if (layers[i].IsTextLayer && callback(layers[i].Index, layers[i].Name, layers[i].Visible))
                {
                    filtered.Add(layers[i]);
                }
            }

            sw.Stop();
            trace("Time for filtering layers: " + sw.ElapsedMilliseconds.ToString() + "ms");
            return(filtered);
        }
Ejemplo n.º 3
0
        public Bitmap Render(Stream s, out IList<IPsdLayer> layers, out Size size,ShowLayerDelegate showLayerCallback, ComposeLayerDelegate composeLayer)
        {
            PsdFile file = new PsdFile();
            file.Load(s);
            //Start with a transparent bitmap (not all PSD files have background layers)
            size = new Size(file.Columns, file.Rows);
            Bitmap b = new Bitmap(file.Columns, file.Rows);

            //ImageDecoder.DecodeImage(file.Layers[0]); //Layers collection doesn't include the composed layer

            Graphics g = Graphics.FromImage(b);
            using (g){
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                for (int i = 0; i < file.Layers.Count; i++)
                {
                    if (showLayerCallback(i,file.Layers[i].Name,file.Layers[i].Visible)){
                        using (Bitmap frame = ImageDecoder.DecodeImage(file.Layers[i])){
                            composeLayer(g, frame, file.Layers[i]);
                        }
                    }
                }
            }
            layers = getLayers(file);
            return b;
        }