你可以打开一个JPEG,添加文本,并重新保存为JPEG的.NET? [英] Can you open a JPEG, add text, and resave as a JPEG in .NET?
本文介绍了你可以打开一个JPEG,添加文本,并重新保存为JPEG的.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写在.NET 4.0中的一个小程序,这将打开.jpg(或.jpeg)文件中添加一行文字到图像,然后重新保存图像为.jpg。有谁知道这样做的最简单的方法是什么?
I want to write a small program in .NET 4.0 that will open a .jpg (or .jpeg) file, add a line of text to the image, and then resave the image as a .jpg. Does anyone know the easiest way to do this?
感谢您的帮助。
推荐答案
事情是这样的:
var filePath = @"D:\Pictures\Backgrounds\abc.jpg";
Bitmap bitmap = null;
// Create from a stream so we don't keep a lock on the file.
using (var stream = File.OpenRead(filePath))
{
bitmap = (Bitmap)Bitmap.FromStream(stream);
}
using (bitmap)
using (var graphics = Graphics.FromImage(bitmap))
using (var font = new Font("Arial", 20, FontStyle.Regular))
{
// Do what you want using the Graphics object here.
graphics.DrawString("Hello World!", font, Brushes.Red, 0, 0);
// Important part!
bitmap.Save(filePath);
}
这篇关于你可以打开一个JPEG,添加文本,并重新保存为JPEG的.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文