gpt4 book ai didi

c# - 生成图像后打印图像 [c#]

转载 作者:太空狗 更新时间:2023-10-30 00:12:28 24 4
gpt4 key购买 nike

我有以下加载空白模板图像的方法,在其上绘制相关信息并将其保存到另一个文件。我想稍微改变一下以实现以下目标:

  • 载入模板图片
  • 在上面画上相关信息
  • 打印出来

不想保存,直接打印出来。这是我现有的方法:

public static void GenerateCard(string recipient, string nominee, string reason, out string filename)
{
// Get a bitmap.
Bitmap bmp1 = new Bitmap("template.jpg");

Graphics graphicImage;

// Wrapped in a using statement to automatically take care of IDisposable and cleanup
using (graphicImage = Graphics.FromImage(bmp1))
{
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);

// Create an Encoder object based on the GUID
// for the Quality parameter category.
Encoder myEncoder = Encoder.Quality;

graphicImage.DrawString(recipient, new Font("Arial", 10, FontStyle.Regular), SystemBrushes.WindowText, new Point(480, 33));
graphicImage.DrawString(WordWrap(reason, 35), new Font("Arial", 10, FontStyle.Regular), SystemBrushes.WindowText, new Point(566, 53));
graphicImage.DrawString(nominee, new Font("Arial", 10, FontStyle.Regular), SystemBrushes.WindowText, new Point(492, 405));
graphicImage.DrawString(DateTime.Now.ToShortDateString(), new Font("Arial", 10, FontStyle.Regular), SystemBrushes.WindowText, new Point(490, 425));
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 100L);
myEncoderParameters.Param[0] = myEncoderParameter;

filename = recipient + " - " + DateTime.Now.ToShortDateString().Replace("/", "-") + ".jpg";

bmp1.Save(filename, jgpEncoder, myEncoderParameters);
}
}

希望能帮到你,布雷特

最佳答案

不保存直接打印到打印机

这是我能想到的最简单的例子。

Bitmap b = new Bitmap(100, 100);
using (var g = Graphics.FromImage(b))
{
g.DrawString("Hello", this.Font, Brushes.Black, new PointF(0, 0));
}

PrintDocument pd = new PrintDocument();
pd.PrintPage += (object printSender, PrintPageEventArgs printE) =>
{
printE.Graphics.DrawImageUnscaled(b, new Point(0, 0));
};

PrintDialog dialog = new PrintDialog();
dialog.ShowDialog();
pd.PrinterSettings = dialog.PrinterSettings;
pd.Print();

关于c# - 生成图像后打印图像 [c#],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4803449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com