使用 asp.net 圆形图像
我可以使用 asp.net 创建圆形图像吗?请指教。我的要求是上传任何图像并获得在 asp.net 上创建的图像的圆形版本。我正在使用 .Net Framework 3.5、Visual Studio .net 2008。
提前非常感谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如其他答案所建议的那样,使用 GDI+ 进行绘图和图像处理非常简单。
但请注意,这是一个不受支持的路径,如这篇 MSDN 文章<所述/a> (重点是我自己添加的)。
我已经在 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).
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.
至少你可以用 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/
首先,您必须找到一个可以对图像执行此类操作的库。
我在 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.
您没有提到这是否是网络,但您是否考虑过使用 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?