/******************************************************
* EasyX Library for C++ (Ver:20100825)
* http://www.easyx.cn
*
* graphics.h
* 在 VC 下模拟 Borland BGI 绘图库,实现简单的绘图
******************************************************/
#pragma once
#ifndef WINVER
#define WINVER 0x0400 // Specifies that the minimum required platform is Windows 95/NT4.
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400 // Specifies that the minimum required platform is Windows 95/NT4.
#endif
#ifndef _WIN32_WINDOWS
#define _WIN32_WINDOWS 0x0410 // Specifies that the minimum required platform is Windows 98.
#endif
#if defined(_UNICODE) && (_MSC_VER > 1200)
#pragma comment(lib,"graphicswu.lib")
#elif !defined(_UNICODE) && (_MSC_VER > 1200)
#pragma comment(lib,"graphicsw.lib")
#elif defined(_UNICODE)
#pragma comment(lib,"graphicsu.lib")
#elif !defined(_UNICODE)
#pragma comment(lib,"graphics.lib")
#endif
#include "windows.h"
#include "tchar.h"
#define PI 3.1415926535
// 为了兼容 Borland C++ 3.1 而做的无意义定义
#define DETECT 0
#define VGA 0
#define VGAHI 0
// 绘图环境初始化参数
#define SHOWCONSOLE 1 // 进入图形模式时,保留控制台的显示
// 颜色
#define BLACK 0
#define BLUE 0xA80000
#define GREEN 0x00A800
#define CYAN 0xA8A800
#define RED 0x0000A8
#define MAGENTA 0xA800A8
#define BROWN 0x0054A8
#define LIGHTGRAY 0xA8A8A8
#define DARKGRAY 0x545454
#define LIGHTBLUE 0xFC5454
#define LIGHTGREEN 0x54FC54
#define LIGHTCYAN 0xFCFC54
#define LIGHTRED 0x5454FC
#define LIGHTMAGENTA 0xFC54FC
#define YELLOW 0x54FCFC
#define WHITE 0xFCFCFC
// 填充模式
#define NULL_FILL 1 // 不填充
#define SOLID_FILL 2 // 用指定颜色完全填充
#define BDIAGONAL_FILL 3 // /// 填充 (普通一组)
#define CROSS_FILL 4 // +++ 填充
#define DIAGCROSS_FILL 5 // xxx 填充
#define DOT_FILL 6 // ... 填充
#define FDIAGONAL_FILL 7 // \\\ 填充
#define HORIZONTAL_FILL 8 // --- 填充
#define VERTICAL_FILL 9 // ||| 填充
#define BDIAGONAL2_FILL 10 // /// 填充 (密集一组)
#define CROSS2_FILL 11 // +++ 填充
#define DIAGCROSS2_FILL 12 // xxx 填充
#define DOT2_FILL 13 // ... 填充
#define FDIAGONAL2_FILL 14 // \\\ 填充
#define HORIZONTAL2_FILL 15 // --- 填充
#define VERTICAL2_FILL 16 // ||| 填充
#define BDIAGONAL3_FILL 17 // /// 填充 (粗线一组)
#define CROSS3_FILL 18 // +++ 填充
#define DIAGCROSS3_FILL 19 // xxx 填充
#define DOT3_FILL 20 // ... 填充
#define FDIAGONAL3_FILL 21 // \\\ 填充
#define HORIZONTAL3_FILL 22 // --- 填充
#define VERTICAL3_FILL 23 // ||| 填充
#define INTERLEAVE_FILL 24 // xxx 填充 (十分密)
#define PATTERN_FILL 25 // 用指定图案填充
// 绘图模式相关函数
void initgraph(int Width, int Height, int Flag = NULL); // 初始化图形环境
void initgraph(int* gdriver, int* gmode, char* path); // 兼容 Borland C++ 3.1 的重载,默认 640x480@24bit
void closegraph(); // 关闭图形环境
// 绘图环境设置
void cleardevice(); // 清屏
void getviewport(int *pleft, int *ptop, int *pright, int *pbottom, bool *pclip = NULL); // 获取视图信息
void setviewport(int left, int top, int right, int bottom, bool clip = true); // 设置视图
void clearviewport(); // 清空视图
void getlinestyle(int *plinestyle, WORD *pupattern = NULL, int *pthickness = NULL); // 获取当前线形
void setlinestyle(int linestyle, WORD upattern = NULL, int thickness = 1); // 设置当前线形
void getfillstyle(COLORREF *pcolor, int *ppattern = NULL, char *pupattern = NULL); // 获取填充类型
void setfillstyle(COLORREF color, int pattern = SOLID_FILL, const char *pupattern = NULL); // 设置填充类型
void getaspectratio(float *pxasp, float *pyasp); // 获取当前缩放因子
void setaspectratio(float xasp = 1, float yasp = 1); // 设置当前缩放因子
void setwritemode(int mode); // 设置绘图位操作模式
void graphdefaults(); // 重置所有绘图设置为默认值
COLORREF getcolor(); // 获取当前绘图前景色
void setcolor(COLORREF color); // 设置当前绘图前景色
COLORREF getbkcolor(); // 获取当前绘图背景色
void setbkcolor(COLORREF color); // 设置当前绘图背景色
void setbkmode(int iBkMode); // 设置背景混合模式
// 颜色模型转换函数
COLORREF RGBtoGRAY(COLORREF rgb);
void RGBtoHSL(COLORREF rgb, float *H, float *S, float *L);
void RGBtoHSV(COLORREF rgb, float *H, float *S, float *V);
COLORREF HSLtoRGB(float H, float S, float L);
COLORREF HSVtoRGB(float H, float S, float V);
// 绘图函数
COLORREF getpixel(int x, int y); // 获取点的颜色
void putpixel(int x, int y, COLORREF color); // 画点
void moveto(int x, int y); // 移动当前点(绝对坐标)
void moverel(int dx, int dy); // 移动当前点(相对坐标)
void line(int x1, int y1, int x2, int y2); // 画线
void linerel(int dx, int dy); // 画线(至相对坐标)
void lineto(int x, int y); // 画线(至绝对坐标)
void rectangle(int left, int top, int right, int bottom); // 画矩形
void getarccoords(int *px, int *py, int *pxstart, int *pystart, int *pxend, int *pyend); // 获取圆弧坐标信息
void arc(int x, int y, int stangle, int endangle, int radius); // 画圆弧
void circle(int x, int y, int radius); // 画圆
void pieslice(int x, int y, int stangle, int endangle, int radius); // 画填充圆扇形
void ellipse(int x, int y, int stangle, int endangle, int xradius, int yradius);// 画椭圆弧线
void fillellipse(int x, int y, int xradius, int yradius); // 画填充椭圆
void sector(int x, int y, int stangle, int endangle, int xradius, int yradius); // 画填充椭圆扇形
void bar(int left, int top, int right, int bottom); // 画无边框填充矩形
void bar3d(int left, int top, int right, int bottom, int depth, bool topflag); // 画有边框三维填充矩形
void drawpoly(int numpoints, const int *polypoints); // 画多边形
void fillpoly(int numpoints, const int *polypoints); // 画填充的多边形
void floodfill(int x, int y, int border); // 填充区域
// 文字相关函数
void outtext(LPCTSTR textstring); // 在当前位置输出文字
void outtext(TCHAR c); // 在当前位置输出字符
void outtextxy(int x, int y, LPCTSTR textstring); // 在指定位置输出文字
void outtextxy(int x, int y, TCHAR c); // 在当前位置输出字符
int textwidth(LPCTSTR textstring); // 获取字符串占用的像素宽
int textheight(LPCTSTR textstring); // 获取字符串占用的像素高
// 设置当前字体样式(详见帮助)
// nHeight: 字符的平均高度;
// nWidth: 字符的平均宽度(0 表示自适应);
// lpszFace: 字体名称;
// nEscapement: 字符串的书写角度(单位 0.1 度);
// nOrientation: 每个字符的书写角度(单位 0.1 度);
// nWeight: 字符的笔画粗细(0 表示默认粗细);
// bItalic: 是否斜体;
// bUnderline: 是否下划线;
// bStrikeOut: 是否删除线;
// fbCharSet: 指定字符集;
// fbOutPrecision: 指定文字的输出精度;
// fbClipPrecision: 指定文字的剪辑精度;
// fbQuality: 指定文字的输出质量;
// fbPitchAndFamily: 指定以常规方式描述字体的字体系列。
void setfont(int nHeight, int nWidth, LPCTSTR lpszFace);
void setfont(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut);
void setfont(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut, BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality, BYTE fbPitchAndFamily);
void setfont(const LOGFONT *font); // 设置当前字体样式
void getfont(LOGFONT *font); // 获取当前字体样式
// 图像处理函数
// 定义图像对象
class IMAGE
{
private:
HBITMAP m_hBmp;
HDC m_hDC;
int m_width, m_height;
public:
IMAGE();
IMAGE(IMAGE &img); // 拷贝构造函数
IMAGE& operator = (IMAGE &img); // 赋值运算符重载函数
~IMAGE();
void getimage(int srcX, int srcY, int srcWidth, int srcHeight);
void getimage(LPCTSTR pImgFile, int zoomWidth = 0, int zoomHeight = 0);
void getimage(LPCTSTR pResType, LPCTSTR pResName, int zoomWidth = 0, int zoomHeight = 0);
void get
C语言graphics图形库
5星 · 超过95%的资源 需积分: 47 201 浏览量
2014-04-21
23:59:21
上传
评论 12
收藏 67KB RAR 举报
faith瑞诚
- 粉丝: 166
- 资源: 13
最新资源
- JavaScript《基于自动分析数据并给出营业建议的餐厅管理系统(接入AI) 》+源代码+项目说明及资料
- 355670834783295707ad04e-427f-4cde-9589-e578224a8459.zip
- 动态sql解析引擎,类似mybatis动态sql的功能
- EDA365-Skill-V2.5安装包,支持Allegro17.x版本
- C# 常用单词汇总,常用单词汇总
- 【ERP标准流程-标准流程-库内业务管理】(DOC 14页).doc
- Python《数据库期末作业-餐厅点单系统 》+源代码+设计资料
- 学生成绩管理系统(C++课程设计
- 双指针法判断链表有环-go语言实现
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页