无法在c ++中显示位图图像

时间:2014-02-22 04:38:36

标签: c++ file

我正在开发一个迷你项目来执行图像平滑,我正在使用位图图像。 我已成功读取图像(作为文本文件),我可以将该图像写入新文件(文本文件)。但是,我希望在平滑后显示输出图像(我使用了一个掩码,一个数组来扫描整个原始图像)“。 有人可以帮我写代码,在执行平滑后“显示”图像吗?

这是我的代码:我的代码构建正确,没有错误

#include <iostream>

#include <fstream>

#include <string>

using namespace std;


void main()

{

    string line1, line2;

int R, C, I;

int values[256][256];

int output[256][256] = {0};


int mask[3][3] = {  -2, -2, -2, 

                    -2,  9, -2,

                    -2, -1, -2 };


ifstream fin("lena256_PGM.pgm");

getline(fin, line1);

getline(fin, line2);

fin >> R >> C >> I;
fin.ignore();


for (int r = 0; r < R; r++ )

    for (int c = 0; c < C; c++ )

        fin >> values[r][c];

fin.close();

for (int r = 0+1; r < R - 1 ; r++ )

    for (int c = 0+1; c < C - 1; c++ )

    {

        int sum = 0;

        int mC = 3;  int mR = 3;

        for (int mr = 0; mr < mR; mr++ )

        for (int mc = 0; mc < mC; mc++ )

                sum += (values[r-1 + mr][c-1 + mc] * mask[mr][mc]);

        output[r][c] = sum < 0? 0 : sum;

    }


ofstream fout("output.pgm");

fout << line1 << endl;

fout << line2 << endl;

fout << R << " " << C << " " << I << endl;

for (int r = 0; r < R; r++ )

    for (int c = 0; c < C; c++ )

        fout << output[r][c] << " ";

system("pause");

fout.close();

}

P2

CREATOR:GIMP PNM过滤器版本1.1

256 256 255 158 165 158 158 158 158 155 158 155 161 155 150 155 155 158 151 150 155 155 150 161 161 174 174 171 167 171 159 151 151 134 117 96 94 90 102 102 108 108 101 108 108 96 108 108 108

0 个答案:

没有答案