切断的图像的中心 [英] Cut a center of a image
本文介绍了切断的图像的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个400x300px形象,我想削减它为200x200px围绕它,在服务器端(C#,.NET 4.0)。
Suppose I have a 400x300px image, and I'd like to cut it as 200x200px centering it, on server side (C#, .NET 4.0).
如何我可以做吗?使用一种帆布和移动? ?任何教程/代码示例/建议
How can I do it? Use a sort of canvas and move it? Any tutorial/code example/suggestions?
推荐答案
尝试是这样的:
Bitmap sourceImage = ...;
int targetWidth = 200;
int targetHeight = 200;
int x = sourceImage.Width / 2 - targetWidth / 2;
int y = sourceImage.Height / 2 - targetHeight / 2;
Rectangle cropArea =
new Rectangle(x, y, targetWidth, targetHeight);
Bitmap targetImage =
sourceImage.Clone(cropArea, sourceImage.PixelFormat);
如果源图像比目标图像尺寸更小,这显然会失败,但你得到的主意。
If the source image is smaller than the target image size, this will obviously fail, but you get the idea.
这篇关于切断的图像的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文