Fetch the repository succeeded.
#include <iostream>
#include <fstream>
using namespace std;
#pragma pack(1)
struct FILEHEADER
{
char dummy1[18]; // 无用信息
int width; // 图像宽
int height; // 图像高
char dummy2[28]; //无用信息
};
struct RGB
{
unsigned char b; // 蓝
unsigned char g; // 绿
unsigned char r; // 红
};
int main()
{
FILEHEADER imgHead1, imgHead2;
RGB pixel1, pixel2, pixel;
float blendRatio = 0.25;
fstream imgFile1, imgFile2, imgFileResult;
imgFile1.open("lighthouse.bmp", ios::in|ios::binary);
imgFile2.open("penguins.bmp", ios::in|ios::binary);
imgFileResult.open("result.bmp", ios::out|ios::binary);
if(!imgFile1 || !imgFile2 || !imgFileResult)
{
cerr<<"File open or create error!"<<endl;
return 0;
}
imgFile1.read((char *)(&imgHead1), sizeof(FILEHEADER));
cout << imgHead1.width << "," << imgHead1.height << endl;
imgFile2.read((char *)(&imgHead2), sizeof(FILEHEADER));
cout << imgHead2.width << "," << imgHead2.height << endl;
if(imgHead1.width!=imgHead2.width || imgHead1.height!=imgHead2.height || imgHead1.width%4!=0) return 0;
imgFileResult.write((char *)(&imgHead1), sizeof(FILEHEADER));
for(int i=0; i<(imgHead1.width*imgHead1.height); i++)
{
imgFile1.read((char *)(&pixel1), sizeof(RGB));
imgFile2.read((char *)(&pixel2), sizeof(RGB));
pixel.b = pixel1.b*blendRatio + pixel2.b*(1-blendRatio);
pixel.g = pixel1.g*blendRatio + pixel2.g*(1-blendRatio);
pixel.r = pixel1.r*blendRatio + pixel2.r*(1-blendRatio);
imgFileResult.write((char *)(&pixel), sizeof(RGB));
}
imgFile1.close();
imgFile2.close();
imgFileResult.close();
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。