bmp_v1/test/image.h

61 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef IMAGE_H
#define IMAGE_H
#include "struct.h"
class Image
{
public:
//构造函数及其重载
Image(){}//创建行列都为零的Image对象
Image(int h, int w);//创建h行w列的Image对象
Image(int h, int w, unsigned char val); //创建的图像像素值都为val;
Image(const char* ImageName); //利用文件名从硬盘加载图像文件成为Image对象;
Image(unsigned char *m, int rows, int cols); //从一维静态数组创建Image对象图像的行数和列数由后面两个参数给出;
Image(unsigned char m[][100], int rows); //从静态二维数组创建Image对象图像的行数二维数组的第一个维度由第二个参数rows给出;
Image(unsigned char **m, int h, int w); //从动态数组二级指针创建Image对象图像的行数和列数由后面两个参数给出;
Image(Image &im); //拷贝构造函数;
~Image(); //析构函数;
void ReadBMP(const char* filename); //从BMP文件中读入图像数据;
void WriteBMP(const char* filename); //将图像数据保存为BMP图像文件;
void WriteBMP(const char *filename, unsigned char** data);//翻转时写图片
void WriteBMP(const char *filename, unsigned char** data,//放缩时写图片
BMPFILEHEADER bmpfileheader, BITMAPINFOHEADER bitmapinfoheader);
void ReadText(const char* filename); //从文本文件中读入图像数据;
void WriteText(const char* filename); //将图像数据保存为文本文件;
unsigned char& At(int row, int col); //获取第row行第col列的像素点的值;
void Set(int row, int col, unsigned char value); //设置像素(row,col)为某值;
void Set(unsigned char value); //设置图像所有像素为同一值;
void Flip(int code); //图像的翻转; 根据code的值0:左右翻转1:上下翻转;
void Resize(int code); //图像的缩放;根据code的值0:缩小一倍1:放大一倍;
void Cut(int x1, int y1, int x2, int y2);//裁剪点(x1,y1)到点(x2,y2)的图像
void Rotate(int degree);//图像旋转的函数简单起见旋转角度为90度的整数倍
void Mean_Variance(float &m, float &var);//求图像的均值和方差,利用参数输出
friend void Swap(Image &a, Image &b);//使用友元函数交换两个Image对象的数据
void myFree(unsigned char** data, int h);
Image& operator=(Image& val);//重载操作符
private:
unsigned char **data;
int height;
int width;
BMPFILEHEADER bmpfileheader;
BITMAPINFOHEADER bitmapinfoheader;
};
#endif