#include <Windows.h>
#include <stdio.h>
typedef struct{
BYTE b;
BYTE g;
BYTE r;
}RGB;
int main( void )
{
BITMAPFILEHEADER fileHeader;
BITMAPINFOHEADER infoHeader;
FILE* pfin = fopen("5.bmp","rb");
if(!pfin)
{
printf("打开文件失败\n");
getchar();
return 0;
}
fread(&fileHeader,sizeof(BITMAPFILEHEADER),1,pfin);
fread(&infoHeader,sizeof(BITMAPINFO),1,pfin);
//为简化代码,只处理24位彩色
if( infoHeader.biBitCount == 24 )
{
int size = infoHeader.biWidth*infoHeader.biHeight;
RGB* img = new RGB[size];
const int smh = ((((infoHeader.biWidth * infoHeader.biBitCount) + 31) & ~31) / 8); //扫描行 字节数 也就是一行数据所需要的字节数 Windows规定一个扫描行所占的字节数必须是4的倍数(即以long为单位),不足的以0填充
for(int i = 0; i < infoHeader.biHeight ;++i)
{
fseek(pfin, fileHeader.bfOffBits + i * smh, SEEK_SET);
fread(img + i * infoHeader.biWidth, sizeof(RGB) , size , pfin );
}
{
HWND hwnd = GetDesktopWindow();
HDC hdc = GetDC(hwnd);
COLORREF color;
int x,y;
while(true)
{
for(int i = 0; i < size; ++i)
{
color = RGB(img[i].r, img[i].g, img[i].b);
x = (i + 1)%infoHeader.biWidth - 1; //扫描从左到右
y = infoHeader.biHeight - (i + 1)/infoHeader.biWidth - 1; //扫描从下到上
if(color != RGB(255, 255, 255)) //白色不画 类似于透明图
SetPixel(hdc, x + 500, y + 500, color);
}
Sleep(100);
}
//释放句柄DC
ReleaseDC(hwnd, hdc);
}
delete[] img;
}
fclose(pfin);
}
#include <stdio.h>
typedef struct{
BYTE b;
BYTE g;
BYTE r;
}RGB;
int main( void )
{
BITMAPFILEHEADER fileHeader;
BITMAPINFOHEADER infoHeader;
FILE* pfin = fopen("5.bmp","rb");
if(!pfin)
{
printf("打开文件失败\n");
getchar();
return 0;
}
fread(&fileHeader,sizeof(BITMAPFILEHEADER),1,pfin);
fread(&infoHeader,sizeof(BITMAPINFO),1,pfin);
//为简化代码,只处理24位彩色
if( infoHeader.biBitCount == 24 )
{
int size = infoHeader.biWidth*infoHeader.biHeight;
RGB* img = new RGB[size];
const int smh = ((((infoHeader.biWidth * infoHeader.biBitCount) + 31) & ~31) / 8); //扫描行 字节数 也就是一行数据所需要的字节数 Windows规定一个扫描行所占的字节数必须是4的倍数(即以long为单位),不足的以0填充
for(int i = 0; i < infoHeader.biHeight ;++i)
{
fseek(pfin, fileHeader.bfOffBits + i * smh, SEEK_SET);
fread(img + i * infoHeader.biWidth, sizeof(RGB) , size , pfin );
}
{
HWND hwnd = GetDesktopWindow();
HDC hdc = GetDC(hwnd);
COLORREF color;
int x,y;
while(true)
{
for(int i = 0; i < size; ++i)
{
color = RGB(img[i].r, img[i].g, img[i].b);
x = (i + 1)%infoHeader.biWidth - 1; //扫描从左到右
y = infoHeader.biHeight - (i + 1)/infoHeader.biWidth - 1; //扫描从下到上
if(color != RGB(255, 255, 255)) //白色不画 类似于透明图
SetPixel(hdc, x + 500, y + 500, color);
}
Sleep(100);
}
//释放句柄DC
ReleaseDC(hwnd, hdc);
}
delete[] img;
}
fclose(pfin);
}