Exemple #1
0
 public Bitmap GetThumbnail(int width, int height, Color background, Color border, int borderWidth)
 {
     lock (this)
     {
         Bitmap   thumb = new Bitmap(width, height);
         Graphics g     = Graphics.FromImage(thumb);
         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
         Renderer.GdiRenderer r = new Renderer.GdiRenderer(g);
         g.Clear(background);
         float isRatio     = Format.Width / Format.Height;
         float shouldRatio = width / (float)height;
         float scale       = 1;
         SizeF ps          = Format.GetPixelSize();
         if (isRatio > shouldRatio)
         {
             float w = ps.Width;
             scale = width / w;
         }
         else
         {
             float h = ps.Height;
             scale = height / h;
         }
         g.TranslateTransform((width - ps.Width * scale) / 2, (height - ps.Height * scale) / 2);
         g.ScaleTransform(scale, scale);
         if (this.BackgroundImage != null)
         {
             r.DrawImage(BackgroundImage,
                         new RectangleF(new PointF(0, 0), Format.GetPixelSize()));
         }
         Color bakCol = this.BackgroundColor1;
         this.BackgroundColor1 = Color.Transparent;
         this.Draw(r);
         this.BackgroundColor1 = bakCol;
         g.ResetTransform();
         using (Pen p = new Pen(border, borderWidth))
         {
             g.DrawRectangle(p, new Rectangle(borderWidth / 2, borderWidth / 2,
                                              width - borderWidth, height - borderWidth));
         }
         return(thumb);
     }
 }
Exemple #2
0
        static void mImage(HttpServer server, RequestHandler handler)
        {
            bool currentVersion = false;

            if (handler.Head.Cookies != null && handler.Head.Cookies.ContainsKey("version"))
            {
                if (handler.Head.Cookies["version"] == pageInfo(ink.Page))
                {
                    currentVersion = true;
                }
            }
            if (currentVersion)
            {
                handler.Response = new HttpResponseNoAnswer(server);
            }
            else
            {
                SizeF size = ink.Page.Format.GetPixelSize();
                using (Bitmap bmp = new Bitmap((int)size.Width, (int)size.Height))
                {
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        g.Clear(Color.White);
                        Renderer.GdiRenderer r = g.GetRenderer();
                        if (ink.Page.BackgroundImage != null)
                        {
                            g.DrawImage(ink.Page.BackgroundImage.GdiBitmap, new RectangleF(new PointF(0, 0), ink.Page.Format.GetPixelSize()));
                        }
                        ink.Page.Draw(r);
                    }

                    handler.Response = new HttpResponsePNG(server, bmp);
                    handler.Response.Head.Cookies.Add("version", pageInfo(ink.Page));
                    handler.Response.Head.Cookies.Add("w", "" + bmp.Width);
                    handler.Response.Head.Cookies.Add("h", "" + bmp.Height);
                }
            }
        }