2

Recently I'm learning skia library(google open source 2d engine,be used on Android and chromium,etc.),Now I want to use it on windows instead of GDI+ dont support clip area with antialias,during it, I find a problem about pixel.

up is set antialias,down is not set antialias

the main code is:

paint.setStrokeWidth(1);
paint.setStyle(SkPaint::kStroke_Style);
paint.setAntiAlias(true);
canvas.drawRect(skrect,paint);  //draw up rect

skrect.fTop += 110;
skrect.fBottom += 110;

paint.setAntiAlias(false);
canvas.drawRect(skrect, paint); //draw down rect

As you see,the same rect,if I not set Antialias,the boundary pixel is 1(I set strock width is 1),but if I set Antialias, the boundary pixel is 2,and it become a bit light,although I set color is black.

I dont konw why,anyone can tell me?

thk,

Morteza Asadi
  • 1,819
  • 2
  • 22
  • 39
李维斯
  • 21
  • 1
  • 2

2 Answers2

1

This happens because OpenGL assumes that each pixel is centered at [0.5; 0.5]. The rasterizer have to draw indeed two pixels and interpolate the alpha. Read more here

If you would like to draw sharp 1px lines with antialiasing turned on just offset coordinates of a line or other figure with 0.5f.

For example a point at [10; 10] should have coordinates [10.5; 10.5] and so on

0

now,maybe I konw.

the skia library canvas should be like Html5`s canvas ,Canvas every line have an infinite thin "line", the width of the line from the center line to stretch,so if we draw a 1px line,in fact,it will fill two of 0.5 pixel point,but the display device dont allow it do that,so it will fill 2 pixel point,and set it color more light to differentiate real 2 pixels .

I will search more material to prove it.

李维斯
  • 21
  • 1
  • 2