// newtest3.6.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "windows.h"
int _tmain(int argc, _TCHAR* argv[])
{
FILE *fp = NULL;
fp=fopen("E:\\Lena.bmp","rb");
unsigned char* pTotal;
pTotal=new unsigned char[786486];
BITMAPFILEHEADER fileHead1;
fileHead1.bfType = 0x4D42;//bmp类型
fileHead1.bfSize= 786486;
fileHead1.bfReserved1 = 0;
fileHead1.bfReserved2 = 0;
fileHead1.bfOffBits=54;//+colorTablesize;
memcpy(pTotal, &fileHead1, 14);
BITMAPINFOHEADER head1;
head1.biBitCount=24;
head1.biClrImportant=0;
head1.biClrUsed=0;
head1.biCompression=0;
head1.biHeight=512;//height;
head1.biPlanes=1;
head1.biSize=40;//40;
head1.biSizeImage=1536*512;//lineByte*height;
head1.biWidth=512;//width;
head1.biXPelsPerMeter=0;
head1.biYPelsPerMeter=0;
memcpy(pTotal+14, &head1, 40);
fseek(fp,54,0);
unsigned char* p40;
p40=new unsigned char[786432];
fread(p40,786432,1,fp);
memcpy(pTotal+54, p40, 786432);
FILE *fp2=fopen("E:\\new.bmp","wb");
fwrite(pTotal,786486,1, fp2);
fclose(fp2);
IplImage *iplImg=0;
iplImg=cvCreateImageHeader(cvSize(512,512),IPL_DEPTH_8U,3);
iplImg->origin=1;//
iplImg->imageData=(char*)malloc(iplImg->imageSize);
memcpy(iplImg->imageData,p40,iplImg->imageSize);
//显示图片
cvNamedWindow("mainWin", 1);
cvShowImage("mainWin", iplImg);
cvWaitKey(0);
cvDestroyWindow("mainWin");
//cvReleaseImage(&iplImg);
unsigned char* pTotal2;
pTotal2=new unsigned char[786486];
BITMAPFILEHEADER fileHead2;
fileHead2.bfType = 0x4D42;//bmp类型
fileHead2.bfSize= 786486;
fileHead2.bfReserved1 = 0;
fileHead2.bfReserved2 = 0;
fileHead2.bfOffBits=54;//+colorTablesize;
memcpy(pTotal2, &fileHead2, 14);
BITMAPINFOHEADER head2;
head2.biBitCount=24;
head2.biClrImportant=0;
head2.biClrUsed=0;
head2.biCompression=0;
head2.biHeight=512;//height;
head2.biPlanes=1;
head2.biSize=40;//40;
head2.biSizeImage=1536*512;//lineByte*height;
head2.biWidth=512;//width;
head2.biXPelsPerMeter=0;
head2.biYPelsPerMeter=0;
memcpy(pTotal2+14, &head2, 40);
memcpy(pTotal2+54, iplImg->imageData, 786432);
FILE *fp3=fopen("E:\\new1.bmp","wb");
fwrite(pTotal,786486,1, fp3);
delete [] pTotal;
delete [] pTotal2;
delete [] p40;
cvReleaseImageHeader(&iplImg);
fclose(fp3);
return 0;
}
opencvIplImage转化BMP(源代码)
最新推荐文章于 2019-07-17 17:24:22 发布