在 C# 中绘制带有圆角、边框和渐变填充的图像
我到处都看了,用谷歌搜索了所有东西,但找不到任何好东西。 我需要的是一个能够绘制带有边框和渐变填充的圆角图像(图形)的类(每个角不同是一个加号)。
我发现的所有示例都存在一些缺陷(例如质量差、缺少功能等)。
我将使用它与 ashx 一起绘制图像,然后将其显示给用户。
谢谢!
I've looked everywhere and googled everything and couldn't find anything good.
What I need is a class that is able to draw an image (graphics) with rounded corners (different on each corner is a plus) with a border and gradient fill.
All the examples I find have some flaws (like bad quality, missing functionality etc).
I will use this with a ashx that will draw the image and then show it to the user.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GraphicsPath 允许您绘制相对自由的形状,然后可以对其进行填充用渐变画笔。下面的示例代码将创建一个具有两个不同圆角和渐变填充的矩形。
结果如下图:
The GraphicsPath allows you to draw relatively free form shapes which you can then fill with a gradient brush. The below example code will create a rectangle with two differntly rounded corners and a gradient fill.
This result in the following image:
我认为您需要创建自己的方法,使用图形对象并“手动”(阅读“使用代码”)创建图像。最简单的方法是创建一个图形对象,添加一个圆圈,然后在图像的每个象限中添加所需的额外内容,然后将对象分成四份。或者将整个内容作为一张图像返回,然后使用 CSS 精灵将图像放置在具有正确坐标的正确位置(可能是更好的解决方案,因为它减少了对图形库的调用并仅返回一个文件,因此减少了对 Web 的调用服务器)。
I think you'll need to create your own method, using a graphics object and "manually" (read "with code") create the image. Easiest way would be to create a single graphics object, add a circle, then in each quadrant of the image add the extras you need, then split the object into fourths. Or return the whole thing as one image then use CSS sprites to place the image in the right spots with the right coordinates (probably the better solution as it uses less calls to the graphics library and returns just one file, so less calls to the web server).