2017-03-04 129 views
0

我實際上使用Xamarin Forms,並且在我的UWP項目中,我有一個任務將相機拍攝的圖像發送到REST服務。圖像發送正確,但我想在該圖像中添加文字水印,但我真的不知道如何在UWP中實現此功能。該圖像作爲StorageFile類型從系統中檢索。如何將文字水印添加到UWP中的圖像?

我試圖將該圖像文件轉換爲字節數組並將其轉換爲位圖來處理圖像並使用類似繪圖或圖形庫的東西。我可以將圖像轉換爲字節數組,但我甚至無法在UWP項目中使用位圖。

我已經在Xamarin Forms論壇中搜索了UWP中的圖像處理和文本水印,但是我發現的問題沒有得到答覆。你有什麼想法或線索來實現這一目標嗎?

+0

[此視頻](https://channel9.msdn.com/Blogs/OneCode/How-to-add-wartermark-text-or-image-to-a-bitmap-in-Windows-Store-app)可能會有所幫助。 –

回答

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圖像處理任務。