Easyx图片操作

本文介绍Easyx图形库中的图片操作方法,包括图片的加载、保存、显示及双缓冲绘图等。提供了详细的函数说明及一个滚动显示图片的实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Easyx图片操作

1. 图片保存(IMAGE)

class IMAGE(int width = 0, int height = 0);

共有成员

  • getwidth():返回 IMAGE 对象的宽度,以像素为单位。
  • getheight():返回 IMAGE 对象的高度,以像素为单位。
  • operator =:实现 IMAGE 对象的直接赋值。该操作仅拷贝源图像的内容,不拷贝源图像的绘图环境。

2. 图片加载(loadimage)

loadimage函数用于从文件中读取图像

// 从图片文件获取图像(bmp/gif/jpg/png/tif/emf/wmf/ico)
void loadimage(
	IMAGE* pDstImg,			// 保存图像的 IMAGE 对象指针
	LPCTSTR pImgFile,		// 图片文件名
	int nWidth = 0,			// 图片的拉伸宽度
	int nHeight = 0,		// 图片的拉伸高度
	bool bResize = false	// 是否调整 IMAGE 的大小以适应图片
);

// 从资源文件获取图像(bmp/gif/jpg/png/tif/emf/wmf/ico)
void loadimage(
	IMAGE* pDstImg,			// 保存图像的 IMAGE 对象指针
	LPCTSTR pResType,		// 资源类型
	LPCTSTR pResName,		// 资源名称
	int nWidth = 0,			// 图片的拉伸宽度
	int nHeight = 0,		// 图片的拉伸高度
	bool bResize = false	// 是否调整 IMAGE 的大小以适应图片
);

  • pDstImg:保存图像的 IMAGE 对象指针。如果为 NULL,表示图片将读取至绘图窗口。
  • pImgFile:图片文件名。支持 bmp / gif / jpg / png / tif / emf / wmf / ico 格式的图片。gif 格式的图片仅加载第一帧;gif 与 png 均不支持透明。
  • nWidth:图片的拉伸宽度。加载图片后,会拉伸至该宽度。如果为 0,表示使用原图的宽度。
  • nHeight:图片的拉伸高度。加载图片后,会拉伸至该高度。如果为 0,表示使用原图的高度。
  • bResize:是否调整 IMAGE 的大小以适应图片。
  • pResType:图片资源类型。
  • pResName:图片资源名称。
  • 返回值:无

备注

如果创建 IMAGE 对象的时候没有指定宽高,可以通过 Resize 函数设置。

对于没有设置宽高的 IMAGE 对象,执行 loadimage 会将其宽高设置为和读取的图片一样的尺寸。

Resize函数

// 这个函数用于调整指定绘图设备的尺寸。
void Resize(
	IMAGE* pImg,
	int width,
	int height
);
  • pImg:指定要调整尺寸的绘图设备。如果为 NULL,则表示默认绘图窗口。
  • width:指定绘图设备的宽度。
  • height:指定绘图设备的高度。
  • 返回值:无

3. 图片显示(putimage)

// 绘制图像
void putimage(
	int dstX,				// 绘制位置的 x 坐标
	int dstY,				// 绘制位置的 y 坐标
	IMAGE *pSrcImg,			// 要绘制的 IMAGE 对象指针
	DWORD dwRop = SRCCOPY	// 三元光栅操作码
);

// 绘制图像(指定宽高和起始位置)
void putimage(
	int dstX,				// 绘制位置的 x 坐标
	int dstY,				// 绘制位置的 y 坐标
	int dstWidth,			// 绘制的宽度
	int dstHeight,			// 绘制的高度
	IMAGE *pSrcImg,			// 要绘制的 IMAGE 对象指针
	int srcX,				// 绘制内容在 IMAGE 对象中的左上角 x 坐标
	int srcY,				// 绘制内容在 IMAGE 对象中的左上角 y 坐标
	DWORD dwRop = SRCCOPY	// 三元光栅操作码
);

  • 参数看函数原型的注释

备注

三元光栅操作码(即位操作模式),支持全部的 256 种三元光栅操作码,常用的几种如下:

含义
DSTINVERT目标图像 = NOT 目标图像
MERGECOPY目标图像 = 源图像 AND 当前填充颜色
MERGEPAINT目标图像 = 目标图像 OR (NOT 源图像)
NOTSRCCOPY目标图像 = NOT 源图像
NOTSRCERASE目标图像 = NOT (目标图像 OR 源图像)
PATCOPY目标图像 = 当前填充颜色
PATINVERT目标图像 = 目标图像 XOR 当前填充颜色
PATPAINT目标图像 = 目标图像 OR ((NOT 源图像) OR 当前填充颜色)
SRCAND目标图像 = 目标图像 AND 源图像
SRCCOPY目标图像 = 源图像
SRCERASE目标图像 = (NOT 目标图像) AND 源图像
SRCINVERT目标图像 = 目标图像 XOR 源图像
SRCPAINT目标图像 = 目标图像 OR 源图像

注:

  1. AND / OR / NOT / XOR 为布尔运算。
  2. "当前填充颜色"是指通过 setfillcolor 设置的用于当前填充的颜色。
  3. 查看全部的三元光栅操作码请参考这里:三元光栅操作码

4. 双缓冲绘图

BeginBatchDraw

这个函数用于开始批量绘图。执行后,任何绘图操作都将暂时不输出到绘图窗口上,直到执行 FlushBatchDraw 或 EndBatchDraw 才将之前的绘图输出。

void BeginBatchDraw();

EndBatchDraw

这个函数用于结束批量绘制,并执行未完成的绘制任务。

// 结束批量绘制,并执行未完成的绘制任务
void EndBatchDraw();

// 结束批量绘制,并执行指定区域内未完成的绘制任务
void EndBatchDraw(
	int left,
	int top,
	int right,
	int bottom
);
  • left:指定区域的左部 x 坐标。
  • top:指定区域的上部 y 坐标。
  • right:指定区域的右部 x 坐标。
  • bottom:指定区域的下部 y 坐标。
  • 返回值:无

FlushBatchDraw

这个函数用于执行未完成的绘制任务。

// 执行未完成的绘制任务
void FlushBatchDraw();

// 执行指定区域内未完成的绘制任务
void FlushBatchDraw(
	int left,
	int top,
	int right,
	int bottom
); 
  • left:指定区域的左部 x 坐标。
  • top:指定区域的上部 y 坐标。
  • right:指定区域的右部 x 坐标。
  • bottom:指定区域的下部 y 坐标。
  • 返回值:无

5. 实例

#include <easyx.h>
#include <conio.h>

int main(void) {
	// 1. 初始化图形设备
	initgraph(400, 400);
	// 2. to do ......
	IMAGE image;					// 定义存储图片的变量
	loadimage(&image, L"bk.png");	// 加载图片
	int y = -image.getheight() + 400;
	while (true) {
		cleardevice();				// 清屏
		BeginBatchDraw();			// 开始批量绘图
		putimage(0, y, &image);		// 显示图片
		if (y >= -400) y = -image.getheight() + 400;
		else y += 10;
		Sleep(200);
		EndBatchDraw();				// 结束批量绘图
	}
	_getch();

	// 3. 关闭图形化设备,并释放资源
	closegraph();
	return 0;
}

在这里插入图片描述
在这里插入图片描述

类似UltraISO的系统镜像制作U盘启动工具。 Installing an operating system from a USB drive is much more convenient than from a disc, and a bootable drive even enables you to work from a system that does not have an OS installed. Rufus is a small-sized app that enables users to format USB flash disks and create bootable drives rapidly. It provides standard and advanced options alike, to suit the preferences of all skill levels. Format to the desired file system The tool is wrapped in a user-friendly interface that resembles the Format panel found in Windows built-in features. You can select a device, partition scheme and target system type, file system type (FAT32, NTFS, UDF, exFAT), cluster size, and new volume label. Connected devices are detected and selected from a drop-down menu. Be sure to save all important data, because the USB drive is formatted and everything is removed in the process. Compatibility options for old BIOS Basic formatting options enable you to check the device for bad blocks and select the algorithm type (from 1 to 4 passes). Plus, you can set the quick format mode, create an extended label and icon files, as well as create a bootable disk using an ISO or various other disc image types. Advanced tweaks can make Rufus list fixed (non-flash) or unpartitioned USB flash disks, add fixes for old BIOS (e.g. extra partition), and you may use Rufus MBR with a selected BIOS ID. To conclude The program records all activity to a separate panel, and it can be saved to a LOG file. It carries out a formatting task rapidly and error-free, using low system resources. We have not come across any issues during our tests since the utility did not cause Windows to hang or crash. To sum it up, Rufus is a straightforward solution to formatting and creating bootable USB drive, providing users with a series of useful features.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值