direct2d: antialiasing and drawing a line with a 1 pixel stroke
http://xboxforums.create.msdn.com/forums/t/61448.aspx
I'm currently porting a number of custom MFC CStatic-derived controls from GDI+ to Direct2D.
I've noticed when drawing horizontal and vertical lines with a 1 pixel wide stroke that the lines are in fact drawn 2 pixels wide and slightly transparent. The same applies to rectangles and rounded rectangles (diagonal lines seem to be drawn ok). The following code snippet is an example of what I'm trying to do.
D2D1_ROUNDED_RECT TempRect = D2D1::RoundedRect(Rectangle, 4.0F, 4.0F);
CComPtr<ID2D1SolidColorBrush> pTempBrush = NULL;
pRenderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White), &pTempBrush);
pRenderTarget->DrawRoundedRectangle(TempRect, pTempBrush);
pRenderTarget->DrawLine(D2D1::Point2F(Rectangle.left, Rectangle.top), D2D1::Point2F(Rectangle.right, Rectangle.top), pTempBrush, 1.0F);
If a specify a 2 pixel stroke then the lines and rectangles are drawn correctly. That is, exactly 2 pixels wide and 100% opaque.
I've tried playing around with the antialiasing mode on the render target, but if I set the render target as follows:
pRenderTarget->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
then the lines look terrible as they are all jagged.
Is there any way that I can force lines to have a 1 pixel stroke while in antialiased mode?
Regards
Martin
I noticed this too. From what I know you can't force it, but you can get around it by adding/subtracting .5 to your positions.
Eg. here is a rectangle:
| RT->DrawRectangle(&D2D1::RectF(3.5f, 3.5f, 75.5f, 65.5f), Brush, 1, NULL); |
|
In DirectX pixel "positions" are at the center of the pixel. For instance, position 0.0f, 0.0f is the exact center of the upper left pixel.
So, if you try to draw a 1 pixel wide line using a rect from (10,3) to (100,4) the rect doesn't align with the pixels. Instead for each X position it covers half of X,3 and X,4. This is why you are seeing the 2 pixel wide line with half transparency.
To solve this subract half a pixel from your coordinates in both directions.
direct2d: antialiasing and drawing a line with a 1 pixel stroke的更多相关文章
- line tension
<!DOCTYPE html> <html> <head> <title>tension</title> <script type=& ...
- Perfect smooth scrolling in UITableViews
https://medium.com/ios-os-x-development/perfect-smooth-scrolling-in-uitableviews-fd609d5275a5 Diffic ...
- 自定义基本java类-StdDraw.java
/************************************************************************* * Compilation: javac StdD ...
- OpenGL的版本号历史和发展
来源请注明.本文永久地址为http://www.cnblogs.com/vertexshader/articles/2917540.html OpenGL®作为业界最为广泛使用的2D和3D图形接口标准 ...
- 高级UI-画笔Paint
在UI这一块,谈到自定义,就离不开画笔和画布的使用话题,在自定义控件的时候,为了做出炫酷的效果,我们往往会使用画笔和画布,那么这里我们就先来看看画笔的使用吧 简单使用例子 自定义一个View publ ...
- 机器学习实战4:Adaboost提升:病马实例+非均衡分类问题
Adaboost提升算法是机器学习中很好用的两个算法之一,另一个是SVM支持向量机:机器学习面试中也会经常提问到Adaboost的一些原理:另外本文还介绍了一下非平衡分类问题的解决方案,这个问题在面试 ...
- Microsoft Win32 to Microsoft .NET Framework API Map
Microsoft Win32 to Microsoft .NET Framework API Map .NET Development (General) Technical Articles ...
- EEG: electrode positions & Broadmann atlas
Source: http://www.brainm.com/software/pubs/dg/BA_10-20_ROI_Talairach/nearesteeg.htm Area LEFT RIG ...
- UVALive 7261 Xiongnu's Land (扫描线)
Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...
随机推荐
- POJ 2771 最大独立集 匈牙利算法
(为什么最大独立集的背景都是严打搞对象的( _ _)ノ|壁) 思路:匈牙利算法 没什么可说的-- // by SiriusRen #include <cstdio> #include &l ...
- GCC中的弱符号与强符号
GCC中的弱符号与强符号 我们经常在编程中碰到一种情况叫符号重复定义.多个目标文件中含有相同名字全局符号的定义,那么这些目标文件链接的时候将会出现符号重复定义的错误.比如我们在目标文件A和目标文件B都 ...
- Kattis - bela
Bela Young Mirko is a smart, but mischievous boy who often wanders around parks looking for new idea ...
- 密信(MeSince),将取代传统电子邮件
电子邮件发展至今已经有几十年的历史,但仍然是最重要的现代互联网应用之一.在全球范围内,每小时发送的非垃圾邮件数量超过30亿封,从工作场景的使用到个人生活,电子邮件都扮演着不可或缺的角色.但是由于明文电 ...
- 转:用java调用oracle存储过程总结(比较好理解)
这段时间开始学习写存储过程,主要原因还是因为工作需要吧,本来以为很简单的,但几经挫折,豪气消磨殆尽,但总算搞通了,为了避免后来者少走弯路,特记述与此,同时亦对自己进行鼓励. 一:无返回值的存储过程 存 ...
- springMVC传递对象参数
初学java,由于项目紧急,来不及仔细的研究,在传递参数时就老老实实的一个一个的采用@RequestParam注解方式传递,最近认真看了一下,发现java也具有类似Asp.net Mvc传递对象做参数 ...
- React-setState源码的理解
首先举一个最简单的例子: this.state={ a:1 } this.setState({ a:2 }) console.log(this.state.a)//1 可以说setState()操作是 ...
- BZOJ 1030 [JSOI2007]文本生成器 (Trie图+DP)
题目大意:给你一堆字符串,一个串不合法的条件是这些字符串中任意一个是这个串的子串,求合法的串的数量 其实这道题比 [HNOI2008]GT考试 那道题好写一些,但道理是一样的 只不过这道题的答案可以转 ...
- Layui父页面向子页面传参
废话不多说!直接上代码! 父窗体js $('.mytable').on('click', '.editRow', function () { var table = $('#table_id_exam ...
- CSS变量实用指南及注意事项
近年来,一些动态特性已经开始成为 CSS 语言本身的一部分. CSS变量 – 官方的术语为 "自定义属性" – 已经已经加入规范并且具有很好的浏览器支持,而 CSS mixins ...