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:
- How can I crop image without changing its resolution in C#.Net?
- This uses
bitmap.Clone
- This uses
- How to crop an image using C#?
- It has several cropping options:
Graphics.FromImage
andGraphics.DrawImage
bitmap.SetResolution
- It has several cropping options:
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