C ++ is based on the vector graphics library cairo graphics, vector graphics cairo

Source: Internet
Author: User
Tags cairo vector graphics library

C ++ is based on the vector graphics library cairo graphics, vector graphics cairo

// Sudo apt-get install libcairo2-dev // pkg-config -- cflags -- libs cairo //-I/usr/include/cairo-I/usr/include/glib-2.0-I /usr/lib/x86_64-linux-gnu/glib-2.0/include-I/usr/include/pixman-1-I/usr/include/freetype2-I/usr/include/libpng12-lcairo # include <iostream> # include <cairo-svg.h> # define ANGLE (ang) (ang x 3.1415926/180.0) int main (int argc, char ** argv) {cairo_t * cr; cairo_surface_t * surface; Int cheight = 400, cwidth = cheight; surface = (cairo_surface_t *) hour ("Cairo_example.svg", cheight, cwidth); cr = cairo_create (surface); interval * pattern; plain text; int x, y; // fill in the background black cairo_set_source_rgb (cr, 0, 0, 0); cairo_rectangle (cr, 0, 0, cwidth, cheight); cairo_fill (cr ); // cairo_set_source_rgb (cr, 0.5, 0.5, 0.5); // pattern = cairo_pattern_creat E_radial (50, 50, 5, 50, 50, 50); // cairo_pattern_add_color_stop_rgb (pattern, 0, 0.75, 0.15, 0.99); // cairo_pattern_add_color_stop_rgb (pattern, 0.9, 1, 1, 1); // cairo_set_source (cr, pattern); // cairo_fill (cr);/* Writing in the foreground */round (cr, 15); cairo_select_font_face (cr, pattern, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_source_rgb (cr, 0, 0, 1); cair O_move_to (cr, 10, 25); cairo_show_text (cr, "hello"); cairo_move_to (cr, 10, 75); cairo_show_text (cr, "Wikipedia! "); Round (cr, 0, 1, 0); cairo_set_antialias (cr, CAIRO_ANTIALIAS_GOOD); cairo_set_line_width (cr, 2); cairo_move_to (cr, 30, 10 ); cairo_line_to (cr, 100, 80); cairo_stroke (cr); cairo_move_to (cr, 30, 10); cairo_line_to (cr, 230, 80); cairo_stroke (cr); reverse rect; rect. x = 200; rect. y = 200; rect. width = 180; rect. height = 160; cairo_rectangle (cr, rect. x, rect. y, rect. width, rect. height); cairo_stroke (cr); // cairo_fill (cr); cairo_set_source_rgba (cr, 1, 0, 1, 0.5); cairo_set_line_width (cr, 15); int cx = 250, cy = 250, R = 130; cairo_arc (cr, cx, cy, R, ANGLE (0), ANGLE (360); cairo_stroke (cr); cairo_surface_write_to_png (surface, "demo1.png"); cairo_destroy (cr); cairo_surface_destroy (surface); return 0 ;}

Compilation in Ubuntu:

G ++ 'pkg-config -- cflags cairo 'test_cairo.cpp 'pkg-config -- libs cairo'

Note: The above symbol is not a single quotation mark, but under the ESC key on the keyboard ,! /The button on the left of the 1 key.

Running result:



Which of the following statements about "vector image" and "bitmap image" are true?

Vector images, also known as object-oriented images or graphic images, are mathematical defined as a series of points connected by lines. The graphic elements in a Vector file are called objects. Each object is a self-contained entity with attributes such as color, shape, outline, size, and screen position. Since each object is a self-contained entity, you can move and change its attributes multiple times while maintaining its original clarity and curvature without affecting other objects in the legend. These features make vector-based programs especially suited to legend and 3D modeling because they generally require the ability to create and operate on a single object. Vector-based plotting is independent of resolution. This means they can be displayed to the output device at the highest resolution.
What is a bitmap image?
Compared with the vector-based Plotting Program above, editing photo programs like Photoshop are used to process bitmap images. When processing bitmap images, You can optimize minor details, make significant changes, and enhance the effect. Bitmap images, also known as Dot Matrix images or drawn images, are composed of individual points called pixels (image elements. These points can be arranged and colored to form a pattern. When you zoom in the bitmap, You can see countless individual blocks that constitute the entire image. The effect of expanding the bitmap size is to increase the size of a single pixel so that the lines and shapes appear uneven. However, if you view it from a distance, the color and shape of the bitmap image appear continuous. Since each pixel is individually colored, you can select an area at the frequency of each pixel to produce similar photo-like effects, such as deepening shadows and increasing colors. Narrowing down the bitmap size will also make the source image deformation, because this will reduce the size of the entire image by reducing pixels. Likewise, bitmap images are created in the form of an array of pixels, so you cannot perform (such as moving) Local bitmaps separately.
Why do we need to focus on the resolution when processing bitmap?
When processing a bitmap, the quality of the output image depends on the resolution set at the beginning of the processing process. Resolution is a general term that refers to the size of details and information contained in an image file, as well as the degree of detail that can be produced by input, output, or display devices. When bitmap operations are performed, the resolution affects the final output quality and the file size. You need to think twice before processing the bitmap, because the resolution selected for the image is usually accompanied by files throughout the process. Whether you print a bitmap file on a 300 dpi printer or a 2570dpi photo layout device, the file is always printed at the resolution size set during image creation, unless the printer resolution is lower than the image resolution. If you want the final output to look the same as that displayed on the screen, you need to know the relationship between the image resolution and the resolution of different devices before you start to work. Obviously, you don't have to consider so much about vector graphs.

Differences between a vector image and a bitmap
Vector Graphics use functions to record the color, size, and other attributes in the image. Any enlargement or reduction of an object will not make the image distorted or degrade the quality. It does not affect the file size. A vector image has a clear profile and is often used to create some logo images.

Bitmap images are combined into an image by many color grids. Each grid is called a pixel and each pixel has a specific position and color value. If the bitmap image is enlarged, it will find pixels with the same mosaic.
Reference: zhidao.baidu.com/question/7872725.html

10 which of the following statements about vector and bitmap images are false :()

Answer: D. Generally, a vector image occupies less bits than a bitmap. This is one of the advantages of vector image 1.

Supplement: flash cannot create bitmap.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.