#include "bmptrans.h"
#include <STRING>
#include <MATH.H>
using namespace std;
#define WIDTHBYTES(bits) (((bits)+31)/32*4)
namespace bmp{
BmpTrans::BmpTrans(){}
BmpTrans::BmpTrans(char* strFile){
rgbToMatrix = new RgbToMatrix(strFile);
pfile = rgbToMatrix->pfile;
dataOfBmp = rgbToMatrix->dataOfBmp;
nPlantNum = rgbToMatrix->nPlantNum;
bitHead = rgbToMatrix->bitHead;
bitInfoHead = rgbToMatrix->bitInfoHead;
height = rgbToMatrix->height;
width = rgbToMatrix->width;
l_width = rgbToMatrix->l_width;
nData = rgbToMatrix->nData;
pRgb = rgbToMatrix->pRgb;
pColorData = rgbToMatrix->pColorData;
}
BmpTrans::~BmpTrans(){
delete rgbToMatrix;
if (bitInfoHead.biBitCount < 24)
{
delete pRgb;
}
delete pColorData;
delete []dataOfBmp;
}
void BmpTrans::menu(){
int x, y;
for (;;)
{
switch (showMenu())
{
case 1:
cout << endl << "请输入平移量:" << endl;
cout << "x = " << flush;
cin >> x;
cout << "y = " << flush;
cin >> y;
translation(x, y);
break;
case 2:
cout << endl << "请输入平移量:" << endl;
cout << "x = " << flush;
cin >> x;
cout << "y = " << flush;
cin >> y;
magnifyTranslation(x , y);
break;
case 3:
standMirror();
break;
case 4:
verticalMirror();
break;
case 5:
spin();
break;
case 6:
magnifySpin();
break;
case 7:
zhuanzhi();
break;
case 8:
zoom();
break;
case 0:
return;
default:
cout << endl << "选择错误!" << endl;
break;
}
}
}
int BmpTrans::showMenu(){
cout << endl;
cout << " 图像变换" << endl;
cout << "===================" << endl;
cout << "[1] 无放大平移" << endl;
cout << "[2] 放大平移" << endl;
cout << "[3] 水平镜像" << endl;
cout << "[4] 垂直镜像" << endl;
cout << "[5] 无放大旋转" << endl;
cout << "[6] 放大旋转" << endl;
cout << "[7] 图像转置" << endl;
cout << "[8] 图像放缩" << endl;
cout << "[0] 返回" << endl;
cout << "===================" << endl;
cout << "请选择:" << flush;
string strEnter;
cin >> strEnter;
if ("1" == strEnter)
return 1;
else if ("2" == strEnter)
return 2;
else if ("3" == strEnter)
return 3;
else if ("4" == strEnter)
return 4;
else if ("5" == strEnter)
return 5;
else if ("6" == strEnter)
return 6;
else if ("7" == strEnter)
return 7;
else if ("8" == strEnter)
return 8;
else if ("0" == strEnter)
return 0;
else
return -1;
}
/*无放大平移*/
void BmpTrans::translation(int x, int y){
//定义一个二维的结构指针**dataOfBmp2,存放变换后的RGB数据
dataOfBmp2 = new tagRGBQUAD*[height * sizeof(tagRGBQUAD)];
dataOfBmp2[0] = new tagRGBQUAD[width*height*sizeof(tagRGBQUAD)];
for (int j = 1;j < height; j++)
{
dataOfBmp2[j] = dataOfBmp2[j-1] + width;
}
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if( (i-y>=0) && (j-x>=0) && (i-y<height) && (j-x<=width))
dataOfBmp2[i][j] = dataOfBmp[i-y][j-x];
}
}
saveBmp();
}
/*放大平移*/
void BmpTrans::magnifyTranslation(int x, int y){
height = height + abs(y);
width = width + abs(x);
l_width = WIDTHBYTES(width * bitInfoHead.biBitCount);
nData = height * l_width;
bitInfoHead.biHeight = height;
bitInfoHead.biWidth = width;
bitInfoHead.biSize = nData + bitHead.bfOffBits;
//定义一个二维的结构指针**dataOfBmp2,存放变换后的RGB数据
dataOfBmp2 = new tagRGBQUAD*[height * sizeof(tagRGBQUAD)];
dataOfBmp2[0] = new tagRGBQUAD[width*height*sizeof(tagRGBQUAD)];
for (int j = 1;j < height; j++)
{
dataOfBmp2[j] = dataOfBmp2[j-1] + width;
}
for(int i=0;i<height;i++)
{
for(int j=0;j<width;j++)
{
if( y>=0 && x>=0 && i-y>=0 && j-x>=0 )
{
dataOfBmp2[i][j] = dataOfBmp[i-y][j-x];
}
if( y<0 && x>=0 && i-y<height && j-x>=0 )
{
dataOfBmp2[i][j] = dataOfBmp[i][j-x];
}
if( y>=0 && x<0 && i-y>=0 && j-x<width )
{
dataOfBmp2[i][j] = dataOfBmp[i-y][j];
}
if( y<0 && x<0 && i-y<height && j-x<width )
{
dataOfBmp2[i][j] = dataOfBmp[i][j];
}
}
}
saveBmp();
//恢复原图像的大小
height = height - abs(y);
width = width - abs(x);
l_width = WIDTHBYTES(width * bitInfoHead.biBitCount);
nData = height * l_width;
bitInfoHead.biHeight = height;
bitInfoHead.biWidth = width;
bitInfoHead.biSize = nData + bitHead.bfOffBits;
}
/*水平镜像*/
void BmpTrans::standMirror(){
//定义一个二维的结构指针**dataOfBmp2,存放变换后的RGB数据
dataOfBmp2 = new tagRGBQUAD*[height * sizeof(tagRGBQUAD)];
dataOfBmp2[0] = new tagRGBQUAD[width*height*sizeof(tagRGBQUAD)];
for (int j = 1;j < height; j++)
{
dataOfBmp2[j] = dataOfBmp2[j-1] + width;
}
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
dataOfBmp2[y][x] = dataOfBmp[y][width - x - 1];
}
}
saveBmp();
}
/*垂直镜像*/
void BmpTrans::verticalMirror(){
//定义一个二维的结构指针**dataOfBmp2,存放变换后的RGB数据
dataOfBmp2 = new tagRGBQUAD*[height * sizeof(tagRGBQUAD)];
dataOfBmp2[0] = new tagRGBQUAD[width*height*sizeof(tagRGBQUAD)];
for (int j = 1;j < height; j++)
{
dataOfBmp2[j] = dataOfBmp2[j-1] + width;
}
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
dataOfBmp2[y][x] = dataOfBmp[height - y -1][width - x - 1];
}
}
saveBmp();
}
/*无放大旋转*/
void BmpTrans::spin(){
double a;
int m = (int)width / 2;
int n = (int)height / 2; //计算图像中心点坐标
cout << endl << "请输入旋转角度:" << flush;
cin >> a;
a = (a / 180) * 3.1415926;
//定义一个二维的结构指针**dataOfBmp2,存放变换后的RGB数据
dataOfBmp2 = new tagRGBQUAD*[height * sizeof(tagRGBQUAD)];
dataOfBmp2[0] = new tagRGBQUAD[width*height*sizeof(tagRGBQUAD)];
for (int j = 1;j < height; j++)
{
dataOfBmp2[j] = dataOfBmp2[j-1] + width;
}
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int x1 = (int)((x - m) * cos(a) + (y - n) * sin(a) + m);
int y1 = (int)((x - m) * (-sin(a)) + (y - n) * cos(a) + n);
if (x1 >= 0 && x1 < width && y1 >=0 && y1 <height)
{
dataOfBmp2[y][x] = dataOfBmp[y1][x1];
}
}
}
saveBmp();
}
/*放大旋转*/
void BmpTrans::magnifySpin(){
double a;
int m = (int)width / 2;
int n = (int)height / 2; //计算图像中心点坐标
cout << endl << "请输入旋转角度:" << flush;
cin >> a;
a = (a / 180) * 3.1415926;
int height_midd = height;
int width_midd = width;
int x_trans = int(((width-1)-m)*cos(a)+((height-1)-n)*sin(a)) - m;
int y_trans = int(((height-1)-n)*cos(a)-(0-m)*sin(a)) - n;
width = width + 2 * abs(x_trans);
height = height + 2 * abs(y_trans);
m = (int)width / 2;
n = (int)height / 2;
//计算位图的实际宽度并确保它为32的倍数
l_width = WIDTHBYTES(width* bitInfoHead.biBitCount);
nData = height*l_width;
bitInfoHead.biHeight = height;
bitInfoHead.biWidth = width;
bitHead.bfSize =nData + bitHead.bfOffBits;
//定义一个二维的结构指针**dataOfBmp2,存放变换后的RGB数据
dataOfBmp2 = new tagRGBQUAD*[height * sizeof(tagRGBQUAD)];
dataOfBmp2[0] = new tagRGBQUAD[width*height*sizeof(tagRGBQUAD)];
for (int j = 1;j < height; j++)
{
dataOfBmp2[j] = dataOfBmp2[j-1] + width;
}
tagRGBQUAD** dataOfBmp3 = new tagRGBQUAD*[height * sizeof(tagRGBQUAD)];
dataOfBmp3[0] = new tagRGBQUAD[width*height*sizeof(tagRGBQUAD)];
for (j = 1;j < height; j++)
{
dataOfBmp3[j] = dataOfBmp3[j-1] + width;
}
for (int i = 0; i < height - 2 * y_trans; i++)
{
for (int j = 0; j < width - 2 * x_trans; j++)
{
dataOfBmp3[i + y_trans][j + x_trans] = dataOfBmp[i][j];
}
}
for (i = 0; i < height
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
图像处理基础C++.zip (68个子文件)
图像处理基础C++
bmpinformationview.h 514B
24.BMP 42KB
bmpSharpen.h 1KB
32.bmp 758KB
bmpinformationview_console_impl.h 1KB
bmp.dsw 514B
bmp.sln 204B
bmp.ncb 241KB
4.BMP 59KB
bmpSmoothing.cpp 7KB
readbmp.h 2KB
bmpinformation.h 501B
bmpinformation_impl.h 665B
bmp.suo 8KB
bmptrans.cpp 15KB
mainview_console_impl.h 581B
0_2.bmp 41KB
1.bmp 8KB
greyprocessing.h 299B
Debug
greyprocessing.sbr 0B
vc60.pdb 156KB
loadbmp.obj 2KB
histogramModification.obj 288KB
main.sbr 0B
bmptrans.obj 244KB
greyprocessing.obj 89KB
rgbToMartix.sbr 0B
bmp.ilk 1.41MB
histogramModification.sbr 0B
rgbToMartix.obj 18KB
bmp.pdb 1.47MB
vc60.idb 273KB
bmpSmoothing.obj 124KB
bmpSharpen.obj 119KB
bmp.bsc 897KB
bmpSharpen.sbr 0B
bmpinformationview_console_impl.sbr 0B
bmpinformation_impl.sbr 0B
mainview_console_impl.sbr 0B
bmpinformationview_console_impl.obj 138KB
bmp.pch 2.06MB
bmpinformation_impl.obj 168KB
bmp.exe 720KB
bmpSmoothing.sbr 0B
main.obj 12KB
mainview_console_impl.obj 119KB
bmptrans.sbr 0B
readbmp.sbr 0B
readbmp.obj 38KB
histogramModification.h 1KB
bmp.dsp 6KB
bmpinformation_impl.cpp 3KB
readbmp.cpp 590B
0.bmp 43KB
bmp.opt 54KB
bmptrans.h 1KB
bmp.plg 2KB
main.cpp 161B
mainview_console_impl.cpp 1KB
8.BMP 164KB
mainview.h 258B
rgbToMartix.cpp 5KB
bmpSharpen.cpp 4KB
greyprocessing.cpp 5KB
bmpinformationview_console_impl.cpp 11KB
histogramModification.cpp 12KB
rgbToMartix.h 846B
bmpSmoothing.h 1KB
共 68 条
- 1
资源评论
- qingpiaopiao142013-01-14蛮实用的,可以好好学习一下!
- 了不起的小白君2013-04-08BMP 图像处理源码挺好的。。。
- jisuanji_wen2014-10-14学习下,可以参考
RobinTomps
- 粉丝: 13
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功