本文介绍了该程序的输出位图很小,如何放大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Printing;
namespace f_print
{
    public partial class Form1 : Form
    {
        struct MarginsBox
        {
            public float Top;
            public float Left;
            public float Bottom;
            public float Right;
            public float Width;
            public float Height;
        }
        Graphics gfx;
        Bitmap printmap = new Bitmap(850, 1100);
        MarginsBox m = new MarginsBox();
        Font f; // Font object, to store fonts
        PrintDocument pd = new PrintDocument(); // Red line to the printer
        float dpi = 256;//128; // Dots Per Inch
        
        public Form1()
        {
            InitializeComponent();
            Start();
        }
        public void Start()
        {
            printmap.SetResolution(dpi, dpi); // Set the resolution of our paper
            m.Top = 1 * dpi; // Set a 1'' margin, from the top
            m.Left = 1.25f * dpi; // Set a 1.25'' margin, from the left
            m.Bottom = printmap.Height - m.Top; // 1'', from the bottom
            m.Right = printmap.Width - m.Left; // 1.25'', from the right
            m.Width = printmap.Width - (m.Left * 2); // Get the width of our working area
            m.Height = printmap.Height - (m.Top * 2); // Get the height of our working area
            gfx = Graphics.FromImage(printmap); // Transfer the bitmap into canvas
            f = new Font("Verdana", 12); // set the font to Verdana, 12
            gfx.DrawString("Printing Test; Printing Test; Printing Test; Printing Test;", f, Brushes.Black, 
                new RectangleF(m.Left, m.Top, m.Width, m.Height)); // Our text, put it on the canvas
            
            pd.PrintPage += new  PrintPageEventHandler(printDocument1_PrintPage);
            pd.DefaultPageSettings.Color = true; // We want to print in color
            pd.Print(); // Print
            try
            {
                this.FormBorderStyle = FormBorderStyle.Fixed3D;
                this.Name = "frmPrint"; // Our form name
                this.Text = "GCW - Print";
                this.MaximizeBox = false; // We can''t maximize
                this.Size = new Size(400, 400); // Form size                
                this.Show(); // Show the form
            }
            catch (ObjectDisposedException)
            {
            }
        }
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(pictureBox1.Image, new Point(0, 0));
        }
    }
}

推荐答案


这篇关于该程序的输出位图很小,如何放大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 00:40