【问题标题】:How to add a text watermark to an image in UWP?如何在 UWP 中为图像添加文本水印?
【发布时间】:2017-07-24 06:52:56
【问题描述】:

我实际上正在使用 Xamarin Forms,在我的 UWP 项目中,我有一个任务,它将相机拍摄的图像发送到 REST 服务。图像发送正确,但我想在该图像中添加文本水印,但我真的不知道如何在 UWP 中实现这一点。图像作为 StorageFile 类型从系统中检索。

我尝试将该图像文件转换为字节数组并将其转换为位图以处理图像并使用绘图或图形库之类的东西。我可以将图像转换为字节数组,但我什至不能在 UWP 项目中使用位图。

我在 Xamarin Forms 论坛中搜索了有关 UWP 中的图像处理和文本水印的信息,但我发现的问题没有得到解答。您有任何想法或线索来实现这一目标吗?

【问题讨论】:

标签: c# image xamarin uwp xamarin.forms


【解决方案1】:

您可以像这样从文件中获取 BitmapImage 对象:

private static async Task<BitmapImage> ConvertToBitmap(string filename)
{
    StorageFile file = await KnownFolders.DocumentsLibrary.GetFileAsync(filename);

    return await LoadImage(file);
}

private static async Task<BitmapImage> LoadImage(StorageFile file)
{
    BitmapImage bitmapImage = new BitmapImage();
    FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);

    bitmapImage.SetSource(stream);

    return bitmapImage;
}

对于水印和其他图像处理任务,您可以查看Portable AForge.NET Framework

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多