[英]How to edit image in C#
嘿嘿。 我想為報告系統編寫一個程序。 我想在 a.jpg 圖像中顯示結果。 我有很多變量名稱,年齡,性別等等等。
問題來了。。
為什么不用Word呢?
是的。 此結果應為 in.jpg 而不是.docx,因為該圖像將發布在網站上。
應該如何將變量“放置”到圖像上?
這是我想要的一個例子: http://prntscr.com/s8bgze
你可以這樣做:
// load your photo
var photo = new Bitmap("photo.jpg");
// create an image of the desired size
var bitmap = new Bitmap(200, 300);
using (var graphics = Graphics.FromImage(bitmap))
{
// specify the desired quality of the render and text, if you wish
//graphics.CompositingQuality = CompositingQuality.HighQuality;
//graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
// set background color
graphics.Clear(Color.White);
// place photo on image in desired location
graphics.DrawImageUnscaled(photo, 0, 0);
using (var font = new Font("Arial", 12))
{
// draw some text on image
graphics.DrawString("Name: X Y", font, Brushes.Black, 0, 200);
graphics.DrawString("Age: 19", font, Brushes.Black, 0, 230);
// etc
}
}
// save image to file or stream
bitmap.Save("edited.phg", ImageFormat.Png);
您可以使用TextRenderer.DrawText代替Graphics.DrawString方法(它們在文本的繪制方面存在細微差別)。
此外,請勿對包含文本的圖像使用 jpg 格式。 取而代之的是png。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.