.Net和GDI +如何在圆角矩形上绘制内部斜角 [英] .Net and GDI+ how-to draw an inner bevel on rounded rectangle

查看:234
本文介绍了.Net和GDI +如何在圆角矩形上绘制内部斜角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!
我寻求了很多,但没有成功.
我有一个用GraphicsPath制成的圆角矩形,并且想要有一个像在Photoshop中一样的内斜角.
我可以使用PathGradientBrush轻松绘制内部阴影"效果.
内部阴影效果不错,但只有一种颜色.

网络上似乎没有人有答案.

感谢您的想法

Hi !
I sought much, but without success.
I have a rounded rectangle made with a GraphicsPath and I want to have an inner bevel like in Photoshop.
I can easilly drawing an "inner shadow" effect using a PathGradientBrush.
The inner shadow is a good effect, but have only one color.

Nobody on the web seems to have an answer.

Thanks for your ideas

推荐答案

绘制斜角时要考虑两件事:

1.照明效果"在对象的左上半部表现为一种方式,在对象的右下半部表现为另一种方式(变亮UL,变暗LR).

2.您需要多个嵌套的相似路径,这些路径彼此之间由一个像素互相插入(因为通常,将倒角绘制为2个像素宽).

要解决#1问题,您需要(a)找出较深和较浅的颜色,并且(b)将图形路径分成一对UL和LR部件.您还需要(对于#2)路径的确切像素高度和宽度.

要解决#2,您需要使用GDI +的变换将路径的高度和宽度精确地缩放2个像素,并将缩放的路径精确地偏移1个像素-以便新路径完全适合原始路径. br/>
现在,您有四个半路径",其中一对适合另一对,您可以渲染亮/正常/暗/超暗.我将使用Windows''放大镜查看斜角控件的颜色排列,以了解在何处使用哪种颜色.

您可能需要调整路径,以便它们在UL和LR零件之间的切割"端正确连接.考虑到您有圆角,您可能还会发现,您需要在切角处做一些额外的操作,以使光线从浅到深形成可接受的渐变(对于方角框,这绝不是问题).您可能需要制作特殊的角线段才能处理此问题.
There are two things to take into account when drawing bevels:

1. the "lighting effect" behaves one way on the upper left half of the object, and the other way on the lower right half (brightening the UL, darkening the LR).

2. you need multiple, nested, similar paths, that are inset from each other by a single pixel all around (because, typically, bevels are drawn 2 pixels wide).

To address #1 you need to (a) figure out your darker and lighter colors, and (b) split the graphics path in to a pair of UL & LR parts. You will also need (for #2) the exact pixel height and width of the path.

To address #2, you need to use GDI+''s transform to scale the path by exactly 2 pixels in height and width, and to offset the scaled path by exactly 1 pixel - so that the new path fits exactly inside the original.

Now you have four "half paths", with a pair that fits inside the other pair, that you can render light/normal/dark/super-dark. I would use Windows'' magnifier to see the color arrangement of beveled controls to get an idea of what colors to use where.

You''re probably going to have to tweak your paths so that they join correctly at the ''cut'' ends between the UL and LR parts; given that you have rounded corners, you may also find that you need to do something extra at the cut corners to make an acceptable gradient from light to dark (with square cornered boxes this is never an issue). You may may need to make special corner segments to handle this.


这篇关于.Net和GDI +如何在圆角矩形上绘制内部斜角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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