在之前的博客中,我们已经实现了bmp图像的读取与保存,本文在之前的基础上对对人图像的数据区进行处理,达到截取图像部分区域的目的,以便以后的图像处理操作,代码如下:
#include <string.h>
#include <malloc.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<time.h>//时间相关头文件,可用其中函数计算图像处理速度
#include"readbmp.h"
#include"savebmp.h"
void image_cut()
{
unsigned char *imagedata = NULL; //动态分配存储原图片的像素信息的二维数组
unsigned char *imagedataCut = NULL;//动态分配存储裁剪后的图片的像素信息的二维数组
char readPath[] = "D:\\C++_file\\image_deal_C++\\IMAGE_JIEQU\\lunpan.bmp";
readBmp(readPath);
imagedata = pBmpBuf;
//===========================================图片裁剪处理====================================================//
int leftdownx, leftdowny, rightupx, rightupy;/////用户输入数值
int Rleftdownx, Rleftdowny, Rrightupx, Rrightupy;/////转换成实际可以使用数值
cout << "请输入要裁剪的矩形区域的左下角和右上角的坐标(连续四个整数值,如50 50 300 300):" << endl;
cin >> leftdownx;
cin >> leftdowny;
cin >> right