图像水印上的 Xamarin.iOS 图像 [英] Xamarin.iOS Image on Image Watermark
问题描述
如何使用 Xamarin.iOS c# 将 png 图像作为水印添加到更大的图像并将输出保存到设备?
How can I add a png image as a watermark to a larger image using Xamarin.iOS c# and save the output to the device?
我从此处发布的另一个问题中找出了 Xamarin.Android 版本.
I figured out the Xamarin.Android version from another question posted here.
提前致谢!!
推荐答案
使用图像上下文,您可以绘制原始图像,然后在必要位置绘制水印,并从上下文中获取新图像.
Using an image context, you can draw the original, then the watermark at the necessary location and obtain a new image from the context.
var originalImage = UIImage.FromBundle("buymore.jpg");
var watermarkImage = UIImage.FromFile("vs.png");
UIGraphics.BeginImageContextWithOptions(originalImage.Size, true, 1.0f);
originalImage.Draw(CGPoint.Empty);
watermarkImage.Draw(new CGRect(new CGPoint(200, 200), watermarkImage.Size));
var processedImage = UIGraphics.GetImageFromCurrentImageContext();
如果您的原始图像和水印图像大小相同,您可以使用 CIFilter
(CISourceOverCompositing
) 将一个图像叠加"在另一个图像之上(假设您的水印具有白色或 alpha 背景.由于速度原因,这是我的首选方法.
If your original and watermark images are the same size, you can use a CIFilter
(CISourceOverCompositing
) to "overlay" one image on top of another (assuming your watermark has a white or alpha background. This is my preferred method due to the speed.
UIImage processedimage;
using (var filter = new CISourceOverCompositing())
{
filter.Image = new CIImage(UIImage.FromBundle("vs.png"));
filter.BackgroundImage = new CIImage(UIImage.FromBundle("buymore.jpg"));
processedimage = UIImage.FromImage(filter.OutputImage);
}
这篇关于图像水印上的 Xamarin.iOS 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!