4kb image tech question
category: general [glöplog]
What's the best (smallest) way to put a an image on the screen?
MS Paint.
Paint. And a really small brush.
Xernobyl: can you be a bit more specific?
Xernobyl: can you be a bit more specific?
He probably means it in terms of framework overload.
iq posted some code with StretchDIBits here some days ago, that should do fine.
i always did something like that:
Code:
void draw(HDC hDC)
{
for(int x = 0; x < 1024; x++)
{
for(int y = 0; y < 768; y++)
{
SetPixel(hDC, x, y, RGB(0,0,0)));
}
}
}
void main()
{
HDC hDC;
HWND hWnd;
DEVMODE dmScreenSettings;
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = 1024;
dmScreenSettings.dmPelsHeight = 768;
dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
hWnd = CreateWindowExA(0, "edit", NULL, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0, NULL);
hDC = GetDC(hWnd);
ShowCursor(FALSE);
draw(hDC);
while(!GetAsyncKeyState(VK_ESCAPE)) { }
}
ahyes, and i guess iq meant that the draw function could be replaced by
Code:
static BITMAPINFO bmi = { {sizeof(BITMAPINFOHEADER), XRES, -YRES, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, {0,0,0,0} };
StretchDIBits( hDC, 0, 0, XRES, YRES, 0,0, XRES,YRES, buffer, &bmi, DIB_RGB_COLORS, SRCCOPY );
skrebbel: I couldn't get that to work... but it's still commented on my code, and I couldn't take screenshots with the src way.
for taking screenshots replace this line:
with this stuff:
i encountered this issue, too, i think it's a winapi problem...
Code:
while(!GetAsyncKeyState(VK_ESCAPE)) { }
with this stuff:
Code:
MSG msg;
while(GetAsyncKeyState(VK_ESCAPE) == 0)
{
if(PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE))
{
switch(msg.message)
{
case WM_KEYDOWN:
//go = 0;
break;
case WM_PAINT:
break;
}
}
}
i encountered this issue, too, i think it's a winapi problem...
you need to implement your own windows class with a WndProc and an event loop (the PeekMessage+DispatchMessage thing) to be able to get screenshots.
my full code is more or less this one:
it's basically src´s code, just that by making the devmode struct static data I win few bytes (with my compiler+options). There is also that code to take a screenshot.
my full code is more or less this one:
Code:
#include <windows.h>
#define XRES 1280
#define YRES 1024
// #define TAKESCREENSHOT
static const BITMAPINFO bmi = { {sizeof(BITMAPINFOHEADER),XRES,-YRES,1,32,BI_RGB,0,0,0,0,0},{0,0,0,0} };
static DEVMODE screenSettings = {
#if _MSC_VER < 1400
{0},0,0,148,0,0x001c0000,{0},0,0,0,0,0,0,0,0,0,{0},0,32,XRES,YRES,0,0,
#else
{0},0,0,156,0,0x001c0000,{0},0,0,0,0,0,{0},0,32,XRES,YRES,{0},0,
#endif
#if(WINVER >= 0x0400)
0,0,0,0,0,0,
#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)
0,0
#endif
#endif
};
static unsigned int buffer[XRES*YRES];
void renderImage( unsigned int *buffer, int xres, int yres );
void entrypoint( void )
{
if( ChangeDisplaySettings(&screenSettings,CDS_FULLSCREEN)) return;
ShowCursor( 0 );
HDC hDC = GetDC( CreateWindowEx( 0,"static",0,WS_VISIBLE|WS_POPUP|WS_CLIPSIBLINGS|WS_MAXIMIZE,0,0,0,0,0,0,0,0) );
StretchDIBits(hDC,0,0,XRES,SYRES,0,0,XRES,SYRES,buffer,&bmi,DIB_RGB_COLORS,SRCCOPY);
renderImage( buffer, XRES, YRES );
#ifdef TAKESCREENSHOT
static const unsigned char head32[18] = { 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, XRES&255, XRES>>8, YRES&255, YRES>>8, 0x20, 0x00 };
HANDLE h = CreateFile( "out.tga", GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
unsigned long wr; WriteFile( h, head32, 18, &wr, 0 );
for( int i=0; i<YRES; i++ ) WriteFile( h, buffer+XRES*(YRES-1-i), XRES*4, &wr, 0 );
CloseHandle( h );
#endif
do
{
StretchDIBits(hDC,0,0,XRES,YRES,0,0,XRES,YRES,buffer,&bmi,DIB_RGB_COLORS,SRCCOPY);
}while( !GetAsyncKeyState(VK_ESCAPE));
ExitProcess(0);
}
it's basically src´s code, just that by making the devmode struct static data I win few bytes (with my compiler+options). There is also that code to take a screenshot.
i'm curious why it wins few bytes in such a case
I knew it had something to do with the loop, but I was hoping there was a smaller way to get it done.
But you can do your small-version without the PeekMessageA-stuff and include the other code in a bigger version of your 4k gfx. I don't think that anyone gets mad with you if he can't take a screenshot of the small version ;)
You've got a point...
spongebob has a point.
iq: what is the size you can get with your compiller? here: 2.5K with VC9express :\ any one?