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);

 

Re: Direct2D: Antialiasing and drawing a line with a 1 pixel stroke

 
 Waterfox:
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); 

This fixes the problem, but I'm not really sure why I need to do this? It looks like it has something to do with the rectangle not aligning precisely to physical pixel boundaries.

I understand that in Direct2D all drawing is done using device independent pixels (DIP) but I'm drawing to a 96 DPI display therefore there should be a 1:1 mapping between DIPs and physical pixels. In WPF there is a property called UseLayoutRounding which ensures that rounding behaviour aligns to whole pixel boundaries. Is there an equivalent in Direct2D? I haven't been able to find anything.

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的更多相关文章

  1. line tension

    <!DOCTYPE html> <html> <head> <title>tension</title> <script type=& ...

  2. Perfect smooth scrolling in UITableViews

    https://medium.com/ios-os-x-development/perfect-smooth-scrolling-in-uitableviews-fd609d5275a5 Diffic ...

  3. 自定义基本java类-StdDraw.java

    /************************************************************************* * Compilation: javac StdD ...

  4. OpenGL的版本号历史和发展

    来源请注明.本文永久地址为http://www.cnblogs.com/vertexshader/articles/2917540.html OpenGL®作为业界最为广泛使用的2D和3D图形接口标准 ...

  5. 高级UI-画笔Paint

    在UI这一块,谈到自定义,就离不开画笔和画布的使用话题,在自定义控件的时候,为了做出炫酷的效果,我们往往会使用画笔和画布,那么这里我们就先来看看画笔的使用吧 简单使用例子 自定义一个View publ ...

  6. 机器学习实战4:Adaboost提升:病马实例+非均衡分类问题

    Adaboost提升算法是机器学习中很好用的两个算法之一,另一个是SVM支持向量机:机器学习面试中也会经常提问到Adaboost的一些原理:另外本文还介绍了一下非平衡分类问题的解决方案,这个问题在面试 ...

  7. Microsoft Win32 to Microsoft .NET Framework API Map

    Microsoft Win32 to Microsoft .NET Framework API Map .NET Development (General) Technical Articles   ...

  8. EEG: electrode positions & Broadmann atlas

    Source: http://www.brainm.com/software/pubs/dg/BA_10-20_ROI_Talairach/nearesteeg.htm   Area LEFT RIG ...

  9. UVALive 7261 Xiongnu's Land (扫描线)

    Wei Qing (died 106 BC) was a military general of the Western Han dynasty whose campaigns against the ...

随机推荐

  1. 『转』How to Think About Your Career

    开始工作的伊始,逐渐转载及阅读Medium上知名华裔设计师Julie Zhuo的文章,这是她在medium上的介绍:Product design VP @ Facebook. Lover of foo ...

  2. BAT三家互联网公司哪家更注重用户体验?

    这几天百度的用户体验又成了设计圈关注的对象,李彦宏好不容易刷出来的好感度一下子被打入了冰点,通过此次事件,不难看出现在的互联网用户对于产品的体验要求越来越高,作为一名美图秀秀级别选手,很难领悟“好设计 ...

  3. python3 django动态分页引发的list切片下标越界问题

    起先是扒了一个包,动态分页的,但这个包分页之前要加载全部的数据,我这东西后台是个爬虫,不一定浏览的完所以这么做有点浪费资源,于是我改造了一下. # :param obj_count: 获得 条目总数# ...

  4. 【fiddler】 fiddler总是在菜单栏下面弹出提示“The system proxy was changed,click to reenable fiddler capture”--转

    源地址:http://blog.csdn.net/htdeyanlei/article/details/52873060 标签: fiddler 2016-10-20 15:28 2747人阅读 评论 ...

  5. 阿里云数据库MySQL版快速上手!

    MySQL是全球最受欢迎的开源数据库,其在各Web应用中均有广泛部署.阿里云数据库MySQL版基于Alibaba的MySQL源码分支,经过双11高并发.大数据量的考验,拥有优良的性能和吞吐量.除此之外 ...

  6. shell试题

    1.按单词出现频率降序排序! 2.按字母出现频率降序排序! The months of learning in Old Boy education are the few months that I ...

  7. 炫酷 CSS 背景效果的 10 个代码片段

    在现代网页设计中,大背景图设计非常流行.随着高清(现在是4K)显示器的出现,越来越多的网页设计师使用大背景图来填充屏幕. 因为这样可以造成很大的视觉冲击力,并有助于更好的传递所要表现的内容. 但是,如 ...

  8. Python字典嵌套

    import copy menu = { "计算机科学与技术":{ "程序编程":{ "传统语言":{ "C++":&q ...

  9. IDEA使用操作说明(自己总结)

    1.idea导入一个项目后,如何再导入另一个项目 首先,点击File-->new-->Module from Existing Sources...-->找到该项目所在位置,选中该项 ...

  10. Raspberry PI 系列 —— 裸机点亮LED灯

    Raspberry PI 系列 -- 裸机点亮LED灯 背景 近期刚买了Raspberry PI B+,配置执行了官方提供的Raspbian系统,折腾了一周Linux系统,感觉没啥意思,于是就试着想了 ...