예제 #1
0
    public static Bitmap FromBundle(IBundle bundle, Graphics g) {
      // The entities will be drawn to our graphics surface using
      // their locations on the canvas.  We want them to be drawn
      // relative to the 0,0 (upper, left corner) of our image.
      // Therefore, calculate the offset required to position them
      // (normalize) in our image and apply that translation to
      // g2, the GDI+ drawing surface used to paint the entities to
      // the image.  Notice we're actually calculating the offset
      // relative to location 5,5.  We adjusting the image height
      // and widht by 10 to ensure we catch everything, so by using
      // location 5,5 here we kept things centered.
      Point offset = new Point(
          5 - bundle.Rectangle.X,
          5 - bundle.Rectangle.Y);
      Matrix matrix = new Matrix();
      matrix.Translate(offset.X, offset.Y);

      Rectangle bundleArea = bundle.Rectangle;
      // bundleArea.Inflate(5, 5);

      Bitmap image = new Bitmap(
          bundleArea.Width + 10,
          bundleArea.Height + 10,
          g);
      Graphics g2 = Graphics.FromImage(image);
      g2.Transform = matrix;


      // The background color is a weird blue, so I'm filling the
      // entire area first with a white color to get around this.
      g2.Clear(Color.White);
      g2.SmoothingMode = SmoothingMode.HighQuality;
      g2.CompositingQuality = CompositingQuality.HighQuality;
      g2.InterpolationMode = InterpolationMode.HighQualityBicubic;

      // Deselect and set Hovered to 'false' for all entities so 
      // they're drawn to the image in their *normal* state.
      bundle.DeSelectAll();
      bundle.SetHovered(false);
      bundle.Paint(g2);

      g.Flush();
      g2.Flush();
      g.Dispose();
      g2.Dispose();

      //System.IntPtr dc1 = g.GetHdc();

      //System.IntPtr dc2 = g2.GetHdc();

      //BitBlt(dc2, 0, 0, width, height, dc1, 0, 0, 0x00CC0020);

      //g.ReleaseHdc(dc1);

      //g2.ReleaseHdc(dc2);

      //g.Dispose();

      //g2.Dispose();
      return image;
    }
예제 #2
0
        public static Bitmap FromBundle(IBundle bundle, Graphics g)
        {
            // The entities will be drawn to our graphics surface using
            // their locations on the canvas.  We want them to be drawn
            // relative to the 0,0 (upper, left corner) of our image.
            // Therefore, calculate the offset required to position them
            // (normalize) in our image and apply that translation to
            // g2, the GDI+ drawing surface used to paint the entities to
            // the image.  Notice we're actually calculating the offset
            // relative to location 5,5.  We adjusting the image height
            // and widht by 10 to ensure we catch everything, so by using
            // location 5,5 here we kept things centered.
            Point offset = new Point(
                5 - bundle.Rectangle.X,
                5 - bundle.Rectangle.Y);
            Matrix matrix = new Matrix();

            matrix.Translate(offset.X, offset.Y);

            Rectangle bundleArea = bundle.Rectangle;
            // bundleArea.Inflate(5, 5);

            Bitmap image = new Bitmap(
                bundleArea.Width + 10,
                bundleArea.Height + 10,
                g);
            Graphics g2 = Graphics.FromImage(image);

            g2.Transform = matrix;


            // The background color is a weird blue, so I'm filling the
            // entire area first with a white color to get around this.
            g2.Clear(Color.White);
            g2.SmoothingMode      = SmoothingMode.HighQuality;
            g2.CompositingQuality = CompositingQuality.HighQuality;
            g2.InterpolationMode  = InterpolationMode.HighQualityBicubic;

            // Deselect and set Hovered to 'false' for all entities so
            // they're drawn to the image in their *normal* state.
            bundle.DeSelectAll();
            bundle.SetHovered(false);
            bundle.Paint(g2);

            g.Flush();
            g2.Flush();
            g.Dispose();
            g2.Dispose();

            //System.IntPtr dc1 = g.GetHdc();

            //System.IntPtr dc2 = g2.GetHdc();

            //BitBlt(dc2, 0, 0, width, height, dc1, 0, 0, 0x00CC0020);

            //g.ReleaseHdc(dc1);

            //g2.ReleaseHdc(dc2);

            //g.Dispose();

            //g2.Dispose();
            return(image);
        }