scale
Description:
Example: Cartesian coordinate system (I):
public static int main (string[] args) {
// Create a context:
Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 500, 500);
Cairo.Context context = new Cairo.Context (surface);
// Transformations:
context.translate (250, 250);
context.scale (1, -1);
// Y-Axis:
context.move_to (-250, 0);
context.line_to (250, 0);
context.stroke ();
// X-Axis:
context.move_to (0, -250);
context.line_to (0, 250);
context.stroke ();
// P (20, 10)
context.set_source_rgba (0, 0, 0, 1);
context.arc (20, 10, 2, 0, 2*Math.PI);
context.fill ();
// Save the image:
surface.write_to_png ("img.png");
return 0;
}
valac --pkg cairo cartesian-coordinate-system.vala
Example: Scale and rotate:
public static int main (string[] args) {
// Create a context:
Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 256, 256);
Cairo.Context context = new Cairo.Context (surface);
// The image:
string image_path = Path.build_filename (Path.get_dirname (args[0]) , "romedalen.png");
Cairo.ImageSurface image = new Cairo.ImageSurface.from_png (image_path);
int w = image.get_width ();
int h = image.get_height ();
context.translate (128.0, 128.0);
context.rotate (45*Math.PI/180);
context.scale (256.0/w, 256.0/h);
context.translate (-0.5*w, -0.5*h);
context.set_source_surface (image, 0, 0);
context.paint ();
// Save the image:
surface.write_to_png ("img.png");
return 0;
}
valac --pkg cairo image-rotate.vala