IImageProcessingContext 找不到 drawtext方法
时间: 2024-01-03 16:03:16 浏览: 26
非常抱歉,我犯了一个错误,`IImageProcessingContext` 中确实没有 `DrawText` 方法。正确的方法应该是在 `SixLabors.ImageSharp.Drawing.Processing` 命名空间中使用 `DrawText` 方法。以下是修正后的代码:
```
using SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
// 创建一个新的图片对象
using var image = new Image<Rgba32>(width, height);
// 在图片上绘制水印文字
var font = new Font("Arial", 12);
var text = "水印文字";
var center = new PointF(image.Width / 2, image.Height / 2);
var textGraphicOptions = new TextGraphicsOptions()
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
image.Mutate(x => x.DrawText(textGraphicOptions, text, font, Rgba32.White, center));
// 将图片保存到本地
image.Save("watermark.png");
```
请注意,我们现在使用 `SixLabors.ImageSharp.Drawing.Processing` 命名空间中的 `DrawText` 方法来绘制水印文字。希望这次回答能够帮到您!
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)