使用 asp.net 圆形图像

发布于 2024-08-12 05:52:43 字数 134 浏览 3 评论 0 原文

我可以使用 asp.net 创建圆形图像吗?请指教。我的要求是上传任何图像并获得在 asp.net 上创建的图像的圆形版本。我正在使用 .Net Framework 3.5、Visual Studio .net 2008。

提前非常感谢。

Can i create round images with asp.net? Please advise. My requirement is to upload any image and get a rounded version of that created bu asp.net. I am using .Net framework 3.5, visual studio .net 2008.

Many thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

可爱暴击 2024-08-19 05:52:43

正如其他答案所建议的那样,使用 GDI+ 进行绘图和图像处理非常简单。

但请注意,这是一个不受支持的路径,如这篇 MSDN 文章<所述/a> (重点是我自己添加的)。

不支持在 Windows 或 ASP.NET 服务中使用 System.Drawing 命名空间中的类。尝试在这些应用程序类型之一中使用这些类可能会产生意外的问题,例如服务性能下降和运行时异常。

我已经在 ASP.NET 应用程序中成功使用了 GDI+ 多次,并且从未遇到过任何问题,但我想知道这一点还是很好的。

Drawing and image manipulation with GDI+ is straightforward as the other answers suggested.

But please note this is an unsupported path, as stated by this MSDN article (emphasis added by myself).

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.

I have successfully used GDI+ within an ASP.NET application several times, and have never faced any problems, but I guess it's just good to know.

妖妓 2024-08-19 05:52:43

至少你可以用 GDI+ 来做到这一点。简短的回答:使用 .Graphics.SetClip() 设置所需的形状,然后绘制图像。剪切区域之外的所有内容都将被剪掉。

这里有一篇文章讨论了一种可以带来更平滑角落的方法(如果您愿意,甚至可以软化边缘):http://danbystrom.se/2008/08/24/soft-edged-images-in-gdi/

You can do it with GDI+ at least. A short answer: use .Graphics.SetClip() to set your desired shape and then draw you image. Everything outside the clipping region will be cut away.

Here's an article disussing a method that will bring smoother corners (and even softed edges if you like): http://danbystrom.se/2008/08/24/soft-edged-images-in-gdi/

最丧也最甜 2024-08-19 05:52:43

首先,您必须找到一个可以对图像执行此类操作的库。
我在 CodeProject http://www.codeproject.com/KB 上找到了一些东西/GDI-plus/rounded_corners.aspx 但我不确定这是否适用于 asp.net(这基本上是你应该谷歌搜索的东西)。

然后,当您拥有一个库时,您可以完成上传文件的工作,并在上传文件后检查 mime 类型,尝试打开它并使用该库。

First of all you have to find yourself a library that can do such thing to an image.
I've found sth on CodeProject http://www.codeproject.com/KB/GDI-plus/rounded_corners.aspx but I'm not sure if this is going to work with asp.net (that's basically a thing that you should google).

Then when you have a library you do your job with uploading a file and when it's uploaded you check the mime-type, try to open it and use the library.

从此见与不见 2024-08-19 05:52:43

您没有提到这是否是网络,但您是否考虑过使用 css 和/或 javascript 对图像进行四舍五入?一旦删除该图像细节,您就无法将其恢复!如果客户稍后想要不同的夹子形状怎么办?

You haven't mentioned whether this is web or not, but have you considered rounding the images with css and/or javascript? Once you remove that image detail you can't get it back! What if the client wants a different clip shape later?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文