资源简介
地图代数八边形距离变换的实现代码,总体不错哦

代码片段和文件信息
#include “stdio.h“
#include “Windows.h“
unsigned char *Bmp;
unsigned char *Mat;
int bmpWidth;
int bmpHeight;
RGBQUAD *ColorTable;
int biBitCount;
int Matrix[19]; //定义结果矩阵
int MatrixDown[19]={3210322122332223333};//定义八边形左下矩阵
int MatrixUp[19]={3333222332212230123};//定义八边形右上矩阵
int num=0;
int m_byte=0;
int m_width=0;
int loc_x[19] ={ 0 0 0 0 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 };
int loc_y[19] ={ -3 -2 -1 0 -3 -2 -1 0 1 2 3 -2 -1 0 1 2 -1 0 1 };
int lol_x[19]={ -3-3-3-2-2-2-2-2-1-1-1-1-1-1-10000};
int lol_y[19]= {-101-2-1012-3-2-101230123};
//位图的读取
bool ReadBmp(char *bmpName)
{
FILE *fp=fopen(bmpName“r+b“);
if(fp==0)
return 0;
fseek(fpsizeof(BITMAPFILEHEADER)0);
BITMAPINFOHEADER Infohead;
fread(&Infoheadsizeof(BITMAPINFOHEADER)1fp);
bmpWidth=Infohead.biWidth;
bmpHeight=Infohead.biHeight;
biBitCount=Infohead.biBitCount;
int lineByte=(bmpWidth*biBitCount/8+3)/4*4;
if(biBitCount==8)
{
ColorTable=new RGBQUAD[256];
fread(ColorTablesizeof(RGBQUAD)256fp);
}
Bmp=new unsigned char[lineByte*bmpHeight];
Mat=new unsigned char[lineByte*bmpHeight];
fread(Bmp1lineByte*bmpHeightfp);
fclose(fp);
return 1;
}
//位图的写入
bool SaveBmp(char *bmpNameunsigned char *OutBmpint widthint heightint biBitCountRGBQUAD *ColorTable)
{
if(!OutBmp)
return 0;
int colorTablesize=0;
if(biBitCount==8)
colorTablesize=1024;
int lineByte=(width*biBitCount/8+3)/4*4;
FILE *fp=fopen(bmpName“w+b“);
if(fp==0)
return 0;
BITMAPFILEHEADER FileHead;
FileHead.bfType=0x4D42;
FileHead.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+colorTablesize+lineByte*height;
FileHead.bfReserved1=0;
FileHead.bfReserved2=0;
FileHead.bfOffBits=54+colorTablesize;
fwrite(&FileHeadsizeof(BITMAPFILEHEADER)1fp);
BITMAPINFOHEADER Infohead;
Infohead.biBitCount=biBitCount;
Infohead.biClrImportant=0;
Infohead.biClrUsed=0;
Infohead.biCompression=0;
Infohead.biHeight=height;
Infohead.biPlanes=1;
Infohead.biSize=40;
Infohead.biSizeImage=lineByte*height;
Infohead.biWidth=width;
Infohead.biXPelsPerMeter=0;
Infohead.biYPelsPerMeter=0;
fwrite(&Infohead sizeof(BITMAPINFOHEADER)1 fp);
if(biBitCount==8)
fwrite(ColorTable sizeof(RGBQUAD)256 fp);
fwrite(OutBmp height*lineByte 1 fp);
fclose(fp);
return 1;
}
int location(int aint b)
{
if(a<0||b<0||b>=bmpWidth||a>=bmpHeight)
return 255;
else
return *(Mat+a*m_byte+b);
}
//最小值的输出
int MinArray(int Arr[19])
{
int m_min;
m_min=Arr[0];
int k;
for(k=1;k<19;k++)
{
if(m_min>Arr[k])
{
m_min=Arr[k];
num=k;
}
}
if(m_min>255)
m_min=255;
return m_min;
}
void main(int argc char* argv[])
{
printf(“Welcome to use the Program of distance_changing!\n“);
char readPath[]=“C:\\Users\\冷冷的世界\\Desktop\\地图代数实习报告\\tuxi
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 184374 2012-06-14 12:19 距离变换\Debug\Distance_chg.exe
文件 243740 2012-06-14 12:19 距离变换\Debug\Distance_chg.ilk
文件 20569 2012-06-14 12:19 距离变换\Debug\Distance_chg.obj
文件 3660844 2012-05-25 20:33 距离变换\Debug\Distance_chg.pch
文件 484352 2012-06-14 12:19 距离变换\Debug\Distance_chg.pdb
文件 140288 2012-06-14 12:19 距离变换\Debug\vc60.idb
文件 77824 2012-06-14 12:19 距离变换\Debug\vc60.pdb
文件 4479 2012-06-14 12:19 距离变换\Distance_chg.cpp
文件 3473 2012-05-25 20:33 距离变换\Distance_chg.dsp
文件 532 2012-05-25 20:44 距离变换\Distance_chg.dsw
文件 41984 2012-06-14 13:26 距离变换\Distance_chg.ncb
文件 48640 2012-06-14 13:26 距离变换\Distance_chg.opt
文件 1184 2012-06-14 12:19 距离变换\Distance_chg.plg
目录 0 2012-06-14 12:19 距离变换\Debug
目录 0 2012-06-14 13:26 距离变换
----------- --------- ---------- ----- ----
4912283 15
- 上一篇:oursecret
- 下一篇:自定义超简单SearchView搜索框
评论
共有 条评论