您的位置:首页 > 其它

3 .做一个自己的截图软件

2011-05-14 16:30 190 查看
上一节:对图像进行反色,理解调色板

有了前面两节的基础,我们就可以做一个简单的截图软件了。

下面这个函数cut可以按照把(x0,y0),(x1,y1)两个点组成的对角线矩形区域的图像截取出来

输入参数pImg, 输出参数pImg2, w, h是pImg的图像的高度和宽度

输入的时候要求x0<x1<w, y0<y1<h

int cut(unsigned char *pImg, unsigned char *pImg2, int x0, int y0, int x1, int y1, int w, int h)

{

int i, j, cnt=0;

if(x0<0 || x0>w-1 || y0<0 || y0>h-1) return -1;

for(i=y0; i<y1; i++)

for(j=x0; j<x1; j++) pImg2[cnt++]=pImg[i*w+j];

}

这样输出的图像就是宽度为(x1-x0),高度为(y1-y0)的图像了。

可以用下面的代码测试一下

int step3(void)
{
int w, h;
unsigned char *pImg, *pImg2;

printf("step3: test cut image!/n");
pImg= read_bmp("test.bmp", &w, &h);
if(pImg==NULL) return -1;

pImg2=(unsigned char*)malloc(100*100);
cut(pImg, pImg2, 10,10,110,110, w, h);
write_bmp("cut.bmp", pImg2, 100, 100);
free(pImg);
free(pImg2);

return 1;
}

这样就把一个位置于原图像(10,10)-(110,110),大小为100x100的图像截取出来了。并且保存到了cut.bmp中







内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: