剪切特定形状的图像 .NET [英] Clip an image in a specific shape .NET

查看:31
本文介绍了剪切特定形状的图像 .NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 MVC4 项目中有一个页面,用户可以在其中使用文件上传控件添加其公司徽标.这些图像/徽标随后会显示在移动应用程序的地图上.我们需要裁剪这些图像,使它们看起来像一面旗帜.

I have a page in my MVC4 project where user can add its company logo using the file upload control. These images/logos are then shown on map in mobile application. We need to crop these images so that they can look like a Flag.

我们只需要提取标志框内的图像部分,其余部分则保留.

We need to take only the part of image inside the flag frame and leave the rest.

  1. 可以使用 C# 中的代码来完成吗?
  2. 如果是,如何完成.请帮我提供一些代码示例和链接.
  3. 我需要在上传的图像上显示一个标志框,以便用户可以在该框架中调整其图像,以及它想要在框架中的内容.

请向我推荐一些 API 和代码示例.

Please suggest me with some APIs and code samples.

谢谢.

更新:在一些网站,当我们上传个人资料图片时,它会在顶部给我们一个框架,我们可以移动我们选择的图片,以便所需的部分进入该框架.现在当我们上传我们的个人资料图片时,它会被调整到那个大小.我可以在这里做类似的事情吗?在上面的框架中,我可以给出一个标志形状,用户可以移动上传的图像,以获得该框架中所需的图像部分.这是正确的方法吗?我们应该怎么做?我查看了一些 jquery 代码示例,但没有帮助.

Update: In some sites, when we upload profile image, it gives us a frame on top, and the image we have selected can be moved, so that the desired part comes into that frame. Now when we upload our profile image, it gets resized into that size. Can I do something similar here? in the frame above, I can give a flag shape, user can move the uploaded image, to get desired part of image in that frame. Is it right approach? How can we do this? I have looked into some jquery code samples, but no help.

推荐答案

您可以使用 SetClip 函数以 Region 作为参数:

You can use SetClip function with the Region as parameter:

https://msdn.microsoft.com/en-us/library/x1zb278e(v=vs.110).aspx

因此,您需要从 Bitmap 创建 Graphics 对象,使用标志的形状设置剪辑,然后在该 Graphics 对象上绘制图像.仅此而已.

So you need to create Graphics object from Bitmap, set clip with the shape of your flag and then draw image on that Graphics object. That's all.

这篇关于剪切特定形状的图像 .NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆