将图片用文字符号来显示
#include <atlimage.h>
#include<iostream>
#pragma warning(disable:4996)
void main(int argc, char** argv)
{
char* imgpath;
if (argc != 2)
return;
imgpath = argv[1];
const char *h11 = "#@&%8$*0(:-,. ";
int lens = strlen(h11);
char hh = '\n';
CImage img;
img.Load(imgpath);
int w ,h;
w = img.GetWidth() / 230;
h = img.GetHeight() / 80;
int bpp = img.GetBPP();
int rgb_c = bpp / 8;
unsigned char* rgb1 = (unsigned char*)img.GetBits();
int pitch1 = img.GetPitch();
FILE *fp = fopen("1.txt", "wb");
for (int i = 0; i < img.GetHeight(); i+=h)
{
for (int j = 0; j < img.GetWidth(); j+=w)
{
int add = 0;
for (int kkk = 0; kkk < 3; kkk++)
{
add += *(rgb1 + (j * rgb_c) + (i * pitch1) + kkk);
}
add /= 3;
fwrite(&h11[(int)((float)add/255* lens)], 1, 1, fp);
}
fwrite(&hh, 1, 1, fp);
}
img.Destroy();
fclose(fp);
}