I'm working on water marking an image with another image and I can't seem to get it quite right. I'm using the Graphics library to overlay the watermark image over the photo. The photo Stream object is later uploaded as a jpg image to Amazon S3. When I go to look at the image, the photo is there but no water mark is present.
I've tried using both the DrawImage() function and DrawText() to add text as a test but no luck. Are there any issues with this part of the code? Thanks for the help.
public Stream WatermarkImage(Stream img, Stream mark, ImageType type)
{
// watermark the image
using (Image result = Image.FromStream(img))
{
Image markImage = Image.FromStream(mark);
using (Graphics g = Graphics.FromImage(result))
{
// draw mark and get result
g.DrawImage(markImage, new Point(20, 20));
Stream markedResult = new MemoryStream();
result.Save(markedResult, ImageFormat.Jpeg);
// return image
return markedResult;
}
}
}
EDIT: I actually found that this part of the code does work. Instead of saving to S3, I saved it to a file:
result.Save(@"C:\Users\Dan\Documents\Jobs\ZenPhotos\Test\test_watermark" + DateTime.Now.ToString("MM_dd_yyyy_HH_mm") + ".jpg");
The saved file shows the watermarked image. So the problem is in my upload to S3 and is unrelated.
Have a look at Automatically add watermark to an image
Instead of saving it to disk as the example demonstrates, you can return a stream instead if that's what you are after.
Hope it helps.
Cloudinary allows you to manipulate your images on-the-fly using all kind of cool transformations capabilities including overlays & watermarks. See: http://cloudinary.com/blog/adding_watermarks_credits_badges_and_text_overlays_to_images
and: http://cloudinary.com/blog/transform_your_image_overlays_with_on_the_fly_manipulation
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.