各位大佬有没有什么读照片的方法
众所周知,C++没有办法打开照片文件
有没有什么靠谱一点点的方法啊
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
void rgb_init() {
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwInMode, dwOutMode;
GetConsoleMode(hIn, &dwInMode);
GetConsoleMode(hOut, &dwOutMode);
dwInMode |= 0x0200;
dwOutMode |= 0x0004;
SetConsoleMode(hIn, dwInMode);
SetConsoleMode(hOut, dwOutMode);
}
unsigned char *pBmpBuf; //数据表指针
int width, height;
RGBQUAD *pColorTable; //颜色表指针
int biBitCount; //图像类型,每像素位数
bool readBmp(char *bmpName) {
FILE *fp=fopen(bmpName,"rb");
if(fp==0) return 0;
//跳过位图文件头
fseek(fp, sizeof(BITMAPFILEHEADER),0);
//读取位图信息头
BITMAPINFOHEADER head;
fread(&head, sizeof(BITMAPINFOHEADER), 1,fp);
width = head.biWidth;
height = head.biHeight;
biBitCount = head.biBitCount;
int lineByte=(width * biBitCount/8+3)/4*4;
// 申请空间并读取图片信息
pBmpBuf=new unsigned char[lineByte * height];
fread(pBmpBuf,1,lineByte * height,fp);
fclose(fp);
return 1;
} int main() {
Sleep(2000);
char readPath[]="cz.BMP";
readBmp(readPath);
//输出图像的信息
printf("width=%d height=%d biBitCount=%d\n",width,height,biBitCount);
int lineByte=(width*biBitCount/8+3)/4*4;
int R,G,B,n=0;
// 打开文件
if(biBitCount==24){
rgb_init();
for(int i=height-1;i>=0;--i){
for(int j=0;j<width;++j){
R=*(pBmpBuf+i*lineByte+j*3+2);
G=*(pBmpBuf+i*lineByte+j*3+1);
B=*(pBmpBuf+i*lineByte+j*3);
printf("\033[38;2;%d;%d;%dm\033[48;2;%d;%d;%dm#",R,G,B,R,G,B);
} printf("\033[38;2;%d;%d;%dm\033[48;2;%d;%d;%dm\n",255,255,255,0,0,0);
} printf("\033[38;2;%d;%d;%dm\033[48;2;%d;%d;%dm",255,255,255,0,0,0); } else {
printf("biBitCount != 24\n");
exit(1);
} return 0;
}
码风诡异,请各位神犇见谅
网上查了个读取bmp文件的方法
但是输出wprintf效率太低,大概7-8分钟才能加载好
代码中的cz.bmp表示文件名(我读的是cz头像)
bmp文件应该放在exe同目录下
而且代码中的cz.bmp应该更改成你要读取照片的文件名