예제 #1
0
        public BitmapGdi ToBitmapGdi()
        {
            var result = new BitmapGdi(Width, Height);

            result.CopyPixelsFrom(this);
            return(result);
        }
예제 #2
0
        public static BitmapGdi ToBitmapGdi(this BitmapSource src)
        {
            var result = new BitmapGdi(src.PixelWidth, src.PixelHeight);

            result.CopyPixelsFrom(src);
            return(result);
        }
예제 #3
0
        /// <summary>Returns a new blank (transparent) GDI bitmap of the specified size.</summary>
        /// <param name="draw">Optionally a method to draw into the returned image.</param>
        public static BitmapGdi NewBitmapGdi(int width, int height, Action <D.Graphics> draw)
        {
            var result = new BitmapGdi(width, height);

            if (draw != null)
            {
                using (var g = D.Graphics.FromImage(result.Bitmap))
                    draw(g);
            }
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Returns a bitmap containing the specified text drawn using the specified font and brush onto a transparent
        /// image. The image is sized to be as small as possible without running the risk of clipping the text.
        /// </summary>
        public static BitmapGdi TextToBitmap(this D.Graphics graphics, string text, D.Font font, D.Brush brush)
        {
            var size = graphics.MeasureString(text, font); // the default is to include any overhangs into the calculation
            var bmp  = new BitmapGdi((int)size.Width + 1, (int)size.Height + 1);

            using (var g = D.Graphics.FromImage(bmp.Bitmap))
            {
                g.CompositingQuality = graphics.CompositingQuality;
                g.InterpolationMode  = graphics.InterpolationMode;
                g.PixelOffsetMode    = graphics.PixelOffsetMode;
                g.SmoothingMode      = graphics.SmoothingMode;
                g.TextRenderingHint  = graphics.TextRenderingHint;
                g.DrawString(text, font, brush, 0, 0);
            }
            return(bmp);
        }
예제 #5
0
 public BitmapGdi ToBitmapGdi()
 {
     var result = new BitmapGdi(Width, Height);
     result.CopyPixelsFrom(this);
     return result;
 }
예제 #6
0
 /// <summary>A shorthand for drawing an image into a GDI image at coordinate 0,0.</summary>
 public static BitmapGdi DrawImage(this BitmapGdi target, BitmapGdi source)
 {
     using (var g = D.Graphics.FromImage(target.Bitmap))
         g.DrawImageUnscaled(source.Bitmap, 0, 0);
     return(target);
 }
예제 #7
0
 /// <summary>A shorthand for drawing an image at coordinate 0,0.</summary>
 public static void DrawImage(this DrawingContext context, BitmapGdi bmp)
 {
     context.DrawImage(bmp.ToWpf(), new Rect(0, 0, bmp.Width, bmp.Height));
 }
예제 #8
0
 public static BitmapGdi ToBitmapGdi(this BitmapSource src)
 {
     var result = new BitmapGdi(src.PixelWidth, src.PixelHeight);
     result.CopyPixelsFrom(src);
     return result;
 }
예제 #9
0
 /// <summary>
 /// Returns a bitmap containing the specified text drawn using the specified font and brush onto a transparent
 /// image. The image is sized to be as small as possible without running the risk of clipping the text.
 /// </summary>
 public static BitmapGdi TextToBitmap(this D.Graphics graphics, string text, D.Font font, D.Brush brush)
 {
     var size = graphics.MeasureString(text, font); // the default is to include any overhangs into the calculation
     var bmp = new BitmapGdi((int) size.Width + 1, (int) size.Height + 1);
     using (var g = D.Graphics.FromImage(bmp.Bitmap))
     {
         g.CompositingQuality = graphics.CompositingQuality;
         g.InterpolationMode = graphics.InterpolationMode;
         g.PixelOffsetMode = graphics.PixelOffsetMode;
         g.SmoothingMode = graphics.SmoothingMode;
         g.TextRenderingHint = graphics.TextRenderingHint;
         g.DrawString(text, font, brush, 0, 0);
     }
     return bmp;
 }
예제 #10
0
 /// <summary>Returns a new blank (transparent) GDI bitmap of the specified size.</summary>
 /// <param name="draw">Optionally a method to draw into the returned image.</param>
 public static BitmapGdi NewBitmapGdi(int width, int height, Action<D.Graphics> draw)
 {
     var result = new BitmapGdi(width, height);
     if (draw != null)
         using (var g = D.Graphics.FromImage(result.Bitmap))
             draw(g);
     return result;
 }
예제 #11
0
 /// <summary>A shorthand for drawing an image into a GDI image at coordinate 0,0.</summary>
 public static BitmapGdi DrawImage(this BitmapGdi target, BitmapGdi source)
 {
     using (var g = D.Graphics.FromImage(target.Bitmap))
         g.DrawImageUnscaled(source.Bitmap, 0, 0);
     return target;
 }
예제 #12
0
 /// <summary>A shorthand for drawing an image at coordinate 0,0.</summary>
 public static void DrawImage(this DrawingContext context, BitmapGdi bmp)
 {
     context.DrawImage(bmp.ToWpf(), new Rect(0, 0, bmp.Width, bmp.Height));
 }