I'm actually working with Xamarin Forms, and in my UWP project I have a Task that sends an image taken by the camera to a REST Service. The image sends correctly, but I want to add a text watermark in that image, but I really don't have a clue how to achieve this in UWP. The image is retrieved from the system as a StorageFile type.
I've tried to convert that image file into a byte array and convert that to a Bitmap to process the Image and use something like Drawing or Graphics libraries. I could convert the image to a byte array, but I couldn't even use Bitmap in a UWP project.
I have searched in Xamarin Forms forums about image processing in UWP and the text watermark, but the questions that I found are unanswered. Do you have any idea or a clue to achieve this?
You can get a BitmapImage object from a file like this:
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;
}
For watermarking and other image processing tasks you could look into Portable AForge.NET Framework .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.