【发布时间】:2015-08-20 18:18:28
【问题描述】:
我有一张从网络摄像头拍摄的图像。我需要提供放大这张图片的错觉。
由于网络摄像头没有光学变焦,我通过裁剪图像来做到这一点。
这一切都很好。
但在裁剪图像后,我会在图像顶部添加一些日期戳和品牌图像。
问题:如果我裁剪了图像,那么生成的文本和品牌水印会显得非常大。 (品牌形象几乎覆盖了图像水平空间的一半。)
如果我没有裁剪图像,那么它们会显示为正常大小。 (品牌形象约占图片水平尺寸的 1/16。)
这是(当然)因为裁剪后的图像更小,但品牌形象保持不变。 有没有办法裁剪图像以使生成的图像具有相同的“大小”(如上所述)?
我宁愿不必动态调整水印的大小。
我尝试过的:
-
How can I crop image without changing its resolution in C#.Net?
- 这使用
bitmap.Clone
- 这使用
-
How to crop an image using C#?
- 它有几个裁剪选项:
-
Graphics.FromImage和Graphics.DrawImage bitmap.SetResolution
-
- 它有几个裁剪选项:
代码:
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 来自这个 CodeProject:
http://www.codeproject.com/Articles/2927/Creating-a-Watermarked-Photograph-with-GDI-for-NET
【问题讨论】:
-
您想按顺序裁剪、缩放、品牌。
标签: c# .net image-processing bitmap resolution