#include <graphics.h>
#include <conio.h>
#include <windows.h>
typedef HWND (WINAPI *PROCGETCONSOLEWINDOW)();
PROCGETCONSOLEWINDOW GetConsoleWindow;
int main (int args, char *argv[])
{
int i=0;
int temp=0;
int width=800;
int height=600;
for(i=0;i<args;i++)
{
if(strcmp("-p",argv[i])==0)
{
temp=i+1;
}
if(strcmp("-width",argv[i])==0)
{
width=atoi(argv[i+1]);
i++;
}
if(strcmp("-height",argv[i])==0)
{
height=atoi(argv[i+1]);
i++;
}
}
HMODULE hKernel32 = GetModuleHandle("kernel32");
GetConsoleWindow = (PROCGETCONSOLEWINDOW)GetProcAddress(hKernel32,"GetConsoleWindow");
HWND hwnd = GetConsoleWindow();
HDC hdc(GetWindowDC(hwnd));
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO bInfo;
GetConsoleScreenBufferInfo(hOut,&bInfo);
RECT rect;
GetClientRect(hwnd,&rect);
int x=0;
int y=0;
int nowX =5+( bInfo.dwCursorPosition.X) * (rect.right-rect.left)/(bInfo.srWindow.Right-bInfo.srWindow.Left);
int nowY =34+ ( bInfo.dwCursorPosition.Y) * (rect.bottom-rect.top)/(bInfo.srWindow.Bottom-bInfo.srWindow.Top);
initgraph(width, height,SHOWCONSOLE);
HDC hdc1 = GetImageHDC();
loadimage(NULL, argv[temp]);
getch();
for(x=0;x<rect.right-rect.left;x++)
{
for(y=0;y<rect.bottom-rect.top;y++)
{
SetPixel(hdc,nowX+x,nowY+y,getpixel(x,y));
}
}
closegraph();
return 0;
}
命令行刷图工具,VC++
-p | 指定图片路径如 c:\2.jpg |
-width | 图片适应的宽度(默认800) |
-height | 图片适应的高度(默认600) |