0

I have an image I am taking from a webcam. I need to offer the illusion of zooming on this image.

Since the webcam does not have optical zoom, I am doing this by cropping the image.

This all works great.

But after I crop the image, I watermark some a date stamp and a branding image on top of the image.

The Problem: If I have cropped the image, then the resulting text and branding watermark appear very large. (The branding image covers almost half the horizontal space of the image.)

If I have not cropped the image, then they appear the normal size. (The branding image covers about 1/16 of the horizontal size of the image.)

This is (of course) because the cropped image is smaller, but the branding image remains the same size. Is there a way to crop an image so that the resulting image is the same "size" (as explained above)?

I would rather not have to dynamically adjust the size of my watermarking.

What I have tried:

Code:

public static Bitmap CropAtRect(Bitmap bitmap, Rectangle rect)
{
   Bitmap croppedBitmap = bitmap.Clone(rect, bitmap.PixelFormat);
   croppedBitmap.SetResolution(bitmap.HorizontalResolution,bitmap.VerticalResolution);
   return croppedBitmap;
}

private Bitmap BrandImage(Bitmap bitmapImage)
{       
   waterMarker = new WaterMarker();
   Bitmap brandedImage = waterMarker.BrandImage(bitmapImage, DateTime.Now.ToString());
   return brandedImage;
}

WaterMarker comes from this CodeProject:
http://www.codeproject.com/Articles/2927/Creating-a-Watermarked-Photograph-with-GDI-for-NET

Community
  • 1
  • 1
Vaccano
  • 78,325
  • 149
  • 468
  • 850

1 Answers1

1

You are missing a step. Add "Scale" into there.

Instead of Crop -> Brand

Crop -> Scale (resize back to original size) -> Brand

Here is a stack overflow on how scale an image in C#. Resize image proportionally with MaxHeight and MaxWidth constraints

Community
  • 1
  • 1
Jason Geiger
  • 1,912
  • 18
  • 32