Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do setDither,setFilterBitmap and setAntiAlias do in a Canvas?

Usually samples that I see,use this methods when try to draw bitmaps on canvas.For example:

paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);

But I do not know what those three methods do?When I have to use them?

like image 855
Student Student Avatar asked Jun 28 '13 15:06

Student Student


2 Answers

I want to explain that how anti-alias produces a smooth edge, it works by blending the foreground and background colors to create a smoother edge. like if background color is transparent and the foreground color is blue, anti aliasing will make the pixels on the edge go from blue to transparent gradually. This makes the edge look smooth to the eye.

like image 112
Zain Ali Avatar answered Oct 12 '22 03:10

Zain Ali


From the doc

Paint.setAntiAlias

Helper for setFlags(), setting or clearing the ANTI_ALIAS_FLAG bit AntiAliasing smooths out the edges of what is being drawn, but is has no impact on the interior of the shape. See setDither() and setFilterBitmap() to affect how colors are treated.

Paint.setFilterBitmap

Helper for setFlags(), setting or clearing the FILTER_BITMAP_FLAG bit. Filtering affects the sampling of bitmaps when they are transformed. Filtering does not affect how the colors in the bitmap are converted into device pixels. That is dependent on dithering and xfermodes.

Paint.setDither

Helper for setFlags(), setting or clearing the DITHER_FLAG bit Dithering affects how colors that are higher precision than the device are down-sampled. No dithering is generally faster, but higher precision colors are just truncated down (e.g. 8888 -> 565). Dithering tries to distribute the error inherent in this process, to reduce the visual artifacts.

like image 27
stinepike Avatar answered Oct 12 '22 03:10

stinepike