0

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.

big_water
  • 3,024
  • 2
  • 26
  • 44
  • I'm saying this without trying it myself. But I think you might have better luck using a Bitmap object rather than an Image object. I've had success with image manipulation using Bitmap. – Theo Mar 29 '16 at 21:33

2 Answers2

0

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.

Community
  • 1
  • 1
Theo
  • 2,609
  • 1
  • 26
  • 27
0

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

Nadav Ofir
  • 778
  • 4
  • 6
  • I've considered that route for other projects but I think it requires a paid subscription. I'm trying to go the free route since ASP.net actually has some powerful image manipulation. – big_water Apr 01 '16 at 18:00
  • Free subscription will allow you to use these transformations. You will only be required to upgrade based on your usage (e.g. storage, # of processed images/month, etc.) – Nadav Ofir Apr 03 '16 at 08:17