您可以在 .NET 中打开 JPEG、添加文本并重新另存为 JPEG 吗?

发布于 2024-09-16 01:30:14 字数 111 浏览 2 评论 0原文

我想在 .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?

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木緿 2024-09-23 01:30:14

像这样的事情:

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);
}

Something like 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);
}
清秋悲枫 2024-09-23 01:30:14
var myBitmap = new Bitmap("C:\\myImage.jpg");
var g = Graphics.FromImage(myBitmap);
g.DrawString("My\nText", new Font("Tahoma", 40), Brushes.White, new PointF(0, 0));
var myBitmap = new Bitmap("C:\\myImage.jpg");
var g = Graphics.FromImage(myBitmap);
g.DrawString("My\nText", new Font("Tahoma", 40), Brushes.White, new PointF(0, 0));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文