将图片用文字符号来显示

将图片用文字符号来显示

#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);
}

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值