Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use graphics library

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to use the graphics library, in view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

1. First of all, we use the classic example of the graphics library to simply use the graphics library.

# include / / reference the graphics library header file # include int main () {initgraph (640,480); / / create a drawing window with the size of 640x480 pixel circle (200,200,100); / / draw a circle, center (200,200), radius 100 _ getch (); / / press any key to continue closegraph (); / / close the drawing window}

Just like the C language, the graphics library has its own header file, and its header file must be included to use the graphics library, otherwise an error will be reported.

The running results are as follows:

2. Now let's understand some basic concepts of graphics library.

2.1. Color:

2.1.1. You can use defined macros

2.1.2. You can also use RGB values

For example: BLACK 0 black BLACK defined as black macro 0 as hexadecimal representation of RGB value WHITE 0xFFFFFF white WHITE defined as white macro 0xFFFFFF as hexadecimal representation of RGB value

Related information page search RGB, which is an international color standard, long knowledge of it!

The default background color of the graphics library is black and the font is white.

2.2. Coordinates:

The coordinate origin is in the upper left corner of the window, the X axis is positive to the right, the Y axis is positive, and the units of measurement are pixels.

3. Introduction of basic functions

3.1. Graphics drawing related function

# include#includeint main () {initgraph (640,480); / / create a drawing window with the size of 640x480 pixel fillrectangle (100 / / upper left x coordinate, 100 / upper left y coordinate, 200 / lower right x coordinate, 200 / / lower right y coordinate); _ getch () / / Press any key to continue closegraph (); / / close the drawing window}

Learn to read the help documentation (it is automatically generated on the desktop when you install the graphics library):

3.2. Text output correlation function

# include#includeint main () {initgraph (640,480); / / create a drawing window with the size of 640x480 pixel outtextxy (x coordinate of text output, y coordinate of text output, L "I love you" / / input is wide byte); _ getch () / / Press any key to continue closegraph (); / / close the drawing window}

The outtextxy () function can check the help documentation to test the water.

3.3. Image processing correlation function

First of all, understand the IMAGE object. The IMAGE object stores picture information (the object is something in C++. If you don't understand it, think of IMAGE as a class structure).

The picture information can be transmitted to the IMAGE object by loading the picture through the loadimage () function.

IMAGE bk;// gets the image from the picture file (bmp/jpg/gif/emf/wmf/ico) loadimage (& bk / / IMAGE object pointer to save the image, L "bk.jpg", / / the relative path 640 is used here, / / the stretched width of the picture is 480); / / the stretch height of the picture

After loading, you can map it. Here is an example of a map:

# include#includeint main () {IMAGE bk; initgraph (640,480); / / create a drawing window with the size of 640x480 pixel loadimage (& bk, L "bk.jpg", 640,480); / / load picture putimage (0,0, & bk); / / Map getchar (); / / press any key to continue closegraph () / / close the drawing window}

Running result:

This is the answer to the question on how to use the graphics library. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report