digitalmars.D.learn - Set color to a single point in Cairo
- TheDGuy (2/2) Dec 19 2015 Hello,
Hello, is it possible to set the color of a single pixel with Cairo?
Dec 19 2015
On Saturday, 19 December 2015 at 14:16:23 UTC, TheDGuy wrote:is it possible to set the color of a single pixel with Cairo?Not like you would do with a classic canvas (2d grid), because colors are applied with `cairo_fill()` and `cairo_stroke()` on a particular path. but you can define a path that represents a single pixel and fill it: ``` cairo_rectangle (cr, x, y, 1, 1); // 1 pix rectangle cairo_set_source_rgba (cr, 0, 0, 0, 1); // color cairo_fill (cr); // fill the rectangle with source rgba ``` However cairo is node made to be used like this. The workflow is usually more based on stacked layers (1 layer = 1 path) with different filling, different transparency.
Dec 19 2015
On Sunday, 20 December 2015 at 01:17:50 UTC, Basile B. wrote:On Saturday, 19 December 2015 at 14:16:23 UTC, TheDGuy wrote:Thanks for your answer, but a bit disappointing that cairo doesn't offer a real "setPixel" function :(is it possible to set the color of a single pixel with Cairo?Not like you would do with a classic canvas (2d grid), because colors are applied with `cairo_fill()` and `cairo_stroke()` on a particular path. but you can define a path that represents a single pixel and fill it: ``` cairo_rectangle (cr, x, y, 1, 1); // 1 pix rectangle cairo_set_source_rgba (cr, 0, 0, 0, 1); // color cairo_fill (cr); // fill the rectangle with source rgba ``` However cairo is node made to be used like this. The workflow is usually more based on stacked layers (1 layer = 1 path) with different filling, different transparency.
Dec 20 2015
On Sunday, 20 December 2015 at 11:16:06 UTC, TheDGuy wrote:On Sunday, 20 December 2015 at 01:17:50 UTC, Basile B. wrote:Vectorial graphics are like that, they are at a higher level than, for, example, open GL. My experience with such libraries is a bit dusty (for example I made this when I was younger: http://4.bp.blogspot.com/-cmzQAHlaE50/TxcG3vEAA9I/AAAAAAAAQS0/qFxVLeo1JGU/s1600/Gr inPlot%2Bv.2.4.jpg, here it plots some variable shape segments defined by x³-ax²+ax) but I clearly remember that you **never** need to draw a single pixel. A point is either part of the fill or of the border, I mean **always**. However not that internaly cairo uses "pixman" but IDK if you can access it directly. (see http://www.pixman.org/)On Saturday, 19 December 2015 at 14:16:23 UTC, TheDGuy wrote:Thanks for your answer, but a bit disappointing that cairo doesn't offer a real "setPixel" function :(is it possible to set the color of a single pixel with Cairo?Not like you would do with a classic canvas (2d grid), because colors are applied with `cairo_fill()` and `cairo_stroke()` on a particular path. but you can define a path that represents a single pixel and fill it: ``` cairo_rectangle (cr, x, y, 1, 1); // 1 pix rectangle cairo_set_source_rgba (cr, 0, 0, 0, 1); // color cairo_fill (cr); // fill the rectangle with source rgba ``` However cairo is node made to be used like this. The workflow is usually more based on stacked layers (1 layer = 1 path) with different filling, different transparency.
Dec 21 2015
On Sunday, 20 December 2015 at 01:17:50 UTC, Basile B. wrote:On Saturday, 19 December 2015 at 14:16:23 UTC, TheDGuy wrote:I did something similar here : https://github.com/Zardoz89/DEDCPU-16/blob/master/src/lem1802_fontview.d#L287 I need to clean these code...is it possible to set the color of a single pixel with Cairo?Not like you would do with a classic canvas (2d grid), because colors are applied with `cairo_fill()` and `cairo_stroke()` on a particular path. but you can define a path that represents a single pixel and fill it: ``` cairo_rectangle (cr, x, y, 1, 1); // 1 pix rectangle cairo_set_source_rgba (cr, 0, 0, 0, 1); // color cairo_fill (cr); // fill the rectangle with source rgba ``` However cairo is node made to be used like this. The workflow is usually more based on stacked layers (1 layer = 1 path) with different filling, different transparency.
Dec 22 2015