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 ...
随机推荐
- 最简单的启动并连接一个redis的docker容器
启动一个容器: $ sudo docker run --name <name> -d redis 连接一个容器: sudo docker run -it --link <name&g ...
- .NET中的异步操作及线程同步
执行异步操作 CLR使用了WIN的线程处理能力,但保留了与其分离的权利.某些时候CLR的线程与Win的线程不是完全的匹配. 线程的系统开销较大,应限制其数量. 创建:分配并初始化一线程内核对象,保留1 ...
- 「JavaSE 重新出发」05.03.02 在运行时使用反射分析对象
在编写程序时,如果知道想要查看的域名和类型,查看指定的域是一个很容易的事,而利用反射机制可以查看在编译时还不清楚的对象域. java Employee tank = new Employee(&quo ...
- CommonsMultipartFile---用Spring实现文件上传
CommonsMultipartFile Spring提供的读取文件的类,使用方便,依赖spring-web-3.1.2.RELEASE.jar 包路径: java.lang.Object org.s ...
- echart纵坐标标签特别长换行显示
纵坐标 yAxis : [ { type : 'category', data : name, axisLabel: { //坐标轴刻度标签的相关设置. textStyle: { color: '#0 ...
- C语言基础 (4) 原码反码补码与数据类型
1.回顾 使用gcc编译代码 gcc hello.c -o hello windows下编译代码 C语言编译步骤: 预处理(头文件展开,干掉注释) gcc -E hello.c -o hello.i ...
- BootStrap复习总结
Bootstrap3 复习总结: 1. 栅格系统: sm:768px md:992px lg:1200px (响应式布局) 1.横向分割页面的空间. 2.在分割的同时考虑到响应式. 内部实现是12列的 ...
- python matplotlib数据可视化
#基于python3 Matplotlib构建的3D图形: 使用pycharm的小伙伴把sciview给关掉: 因为sciview显示的是png图片.3d图形一般我们都需要拖拖拽拽的. 参见: htt ...
- linux查看前几条命令记录
1.按上下箭头键2.history|more分页显示3.vi /etc/profile找HISTSIZE=1000,说明你最多能存1000条历史记录.4.!!执行最近执行的命令5.history|he ...
- ASP.NET-ActionFilter过滤器用法实例
ActionFilter可以对每一个传过来的action请求进行过滤,非常有用,但是如果在这里判断过多,那么网站的性能和速度会不会变慢,这个问题值得思考,现在先放在这里. public class A ...