Example #1
0
        private Graphics CreateGraphics(Bitmap target, BitmapRendererOptions options)
        {
            var g = Graphics.FromImage(target);

            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode  = InterpolationMode.High;
            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
            g.TextRenderingHint  = TextRenderingHint.ClearTypeGridFit;
            options.ConfigureGraphics?.Invoke(g);
            return(g);
        }
Example #2
0
        public void Render(Form form, Bitmap target, BitmapRendererOptions options = null)
        {
            options = options ?? BitmapRendererOptions.Default;

            using (var localBitmapCache = new BitmapCache())
                using (var g = CreateGraphics(target, options))
                {
                    var context = CreateContext(g, localBitmapCache);
                    form.LayOut(target.Size, context);
                    Render(context, form.Content);
                }
        }
Example #3
0
        public Bitmap Render(Form form, BitmapRendererOptions options = null)
        {
            options = options ?? BitmapRendererOptions.Default;

            using (var localBitmapCache = new BitmapCache())
            {
                using (var refBmp = new Bitmap(1, 1))
                    using (var refGraphics = CreateGraphics(refBmp, options))
                        form.LayOut(new Size(int.MaxValue, int.MaxValue), CreateContext(refGraphics, localBitmapCache));

                var bitmap = new Bitmap(form.Content.DesiredSize.Width, form.Content.DesiredSize.Height,
                                        PixelFormat.Format32bppArgb);
                using (var graphics = CreateGraphics(bitmap, options))
                    Render(CreateContext(graphics, localBitmapCache), form.Content);

                return(bitmap);
            }
        }