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. 【转】在IIS上部署你的ASP.NET Core项目

    概述 与ASP.NET时代不同,ASP.NET Core不再是由IIS工作进程(w3wp.exe)托管,而是使用自托管Web服务器(Kestrel)运行,IIS则是作为反向代理的角色转发请求到Kest ...

  2. Java Servlet 配置

    图片太大,可以右键另存再查看,也可以鼠标点击拖置一下,用浏览器单独承载放大查看.

  3. 七牛上图片总是net::ERR_NAME_NOT_RESOLVED

    七牛上图片总是net::ERR_NAME_NOT_RESOLVED >> php这个答案描述的挺清楚的:http://www.goodpm.net/postreply/php/101000 ...

  4. 401 - Unauthorized: Access is denied due to invalid credentials.

    solution:change application pool from ApplicationPoolIdentity to NetworkService.

  5. IETF透露HTTP over QUIC 将重命名为HTTP/3 协议

    周一,IETF透露它将HTTP-over-QUIC实验协议重命名为HTTP / 3.HTTP-over-QUIC是一种HTTP重写,用TCP替换TCP. 如果这看起来有点为时过早,那么它与IETF的历 ...

  6. Facebook再次爆出安全漏洞,9000万用户受影响

    今年上半年开始,美国社交媒体Facebook因数据泄露事件和涉嫌操纵选举等问题频繁接受听证会拷问,然而事情却远没有结束.今年9月Facebook再次爆出安全漏洞,导致9000万用户可能受到影响. 根据 ...

  7. 一些sass

    # sass #---sass---定义变量:--    $变量名:  : 默认变量    sass的默认变量仅需要在值后面加上!default即可.list--list数据可通过空格,逗号或小括号分 ...

  8. 洛谷1099 [NOIP2007] 树网的核

    链接https://www.luogu.org/problemnew/show/P1099 题目描述 设T=(V,E,W)是一个无圈且连通的无向图(也称为无根树),每条边到有正整数的权,我们称TTT为 ...

  9. 洛谷 P2243 电路维修

    P2243 电路维修 题目背景 Elf 是来自Gliese 星球的少女,由于偶然的原因漂流到了地球上.在她无依无靠的时候,善良的运输队员Mark 和James 收留了她.Elf 很感谢Mark和Jam ...

  10. CentOS 安装SVNclient

    1.检查是已经安装了svn: # rpm -qa subversion subversion-1.7.14-6.el7.x86_64 卸载旧版本号的svn: # yum remove subversi ...