Jump to content
Rpg²S Forum

Screen Capture


Recommended Posts

Ecco un programmino scritto in 10 minuti per lo screen capture, utile per i rip dagli emulatori :D

È GRATUITO e se volete costruirci su un tool sono contento (fate leggere la configurazione da un file di testo e gli create una interfaccia grafica :) ), da linux non è che me ne faccia molto :) (anzi già è tanto se sono riuscito a testarlo :D)

 

Nota

Salva in Bitmaps non compressi che pesano 2-3 mb l'uno, non eccedete con gli screen se non avete molto spazio

 

Modifiche

quante indica il numero di immagini da prendere

refresh indica la pausa tra uno screen e l'altro (pausa di 1000/refresh millisecondi) valori più alti di 100 creano problemi visto che l'orologio di sistema non calcola tempi inferiori a 10 millisecondi e anzi ragiona in blocchi di 10 millisec alla volta

base indica il prefisso degli screen che saranno seguiti da un numero da 0 a quante, in genere breve, se volete metterlo più lungo dovete modificare di conseguenza la dimensione dell'array title (che ho messo già sovrabbondante)

 

Se piuttosto di tutto il desktop volete salvarvi la finestra di un emulatore (consigliato!) allora dovete associare a finestra l'handler dell'emu con FindWindow(NULL,"TitoloPrecisoDellaFinestra"); //potete o andare a tentativi o utilizzare i dati forniti dal task manager

 

Come compilarlo:

gcc -o screen.exe screen.c -lgdi32 -luser32

oppure con project manager selezionate compila come Finestra/Window/GUI e nel linker mettete lgdi32.lib e user32.lib se Visual C++

-lgdi32 -luser32 se Dev C++

(probabilmente manca qualche include di qualche lib di base, con dev c++ e usando gli include di base me la sono cavata)

 

 

screen.c

#include <windows.h>
#include <stdio.h>

//funzioni prese dall'msdn :D
PBITMAPINFO CreateBitmapInfoStruct(HBITMAP hBmp);
int CreateBMPFile(LPTSTR pszFile, PBITMAPINFO pbi,HBITMAP hBMP, HDC hDC);


int WINAPI WinMain (HINSTANCE hThisInstance,
				HINSTANCE hPrevInstance,
				LPSTR lpszArgument,
				int nFunsterStil)

{
				
//----------------------modifica QUI-----------------------
int quante = 10
int refresh = 10;
char base[] = "screen";
char title[256];
//uno dei due
HWND finestra = GetDesktopWindow(); //Desktop
//HWND finestra = FindWindow(NULL,"NomeFinestraEmulatore");

//-------------------NON MODIFICARE E SE VUOI SMETTI DI LEGGERE :D---------------------------


int i,width, height;
RECT dim;
HDC source = GetWindowDC(finestra);
HDC dest = CreateCompatibleDC(source);
GetWindowRect(finestra,&dim);
width = dim.right - dim.left;
height = dim.bottom - dim.top;
HBITMAP img = CreateCompatibleBitmap(source,width,height);


for (i = 0;i<quante; i++){
	SelectObject(dest,img);
	sprintf(title,"%s%3d.bmp",base,i);
	BitBlt(dest,0,0,width,height,source,0,0,SRCCOPY);
	CreateBMPFile(title,CreateBitmapInfoStruct(img),img,dest);

	Sleep(1000/refresh);
}

DeleteObject(img);
DeleteDC(dest);
ReleaseDC(finestra,source);
return 0;		   
}		   

int CreateBMPFile(LPTSTR pszFile, PBITMAPINFO pbi, 
			  HBITMAP hBMP, HDC hDC) 
{ 
 HANDLE hf;				 // file handle 
BITMAPFILEHEADER hdr;	   // bitmap file-header 
PBITMAPINFOHEADER pbih;	 // bitmap info-header 
LPBYTE lpBits;			  // memory pointer 
DWORD dwTotal;			  // total count of bytes 
DWORD cb;				   // incremental count of bytes 
BYTE *hp;				   // byte pointer 
DWORD dwTmp; 

pbih = (PBITMAPINFOHEADER) pbi; 
lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage); 
if (!lpBits) return 1;
// Retrieve the color table (RGBQUAD array) and the bits 
// (array of palette indices) from the DIB. 
if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi, 
	DIB_RGB_COLORS)) 
{
	return 1;
}

// Create the .BMP file. 
hf = CreateFile(pszFile, 
			   GENERIC_READ | GENERIC_WRITE, 
			   (DWORD) 0, 
				NULL, 
			   CREATE_ALWAYS, 
			   FILE_ATTRIBUTE_NORMAL, 
			   (HANDLE) NULL); 
if (hf == INVALID_HANDLE_VALUE) 
	return 1;
hdr.bfType = 0x4d42;		// 0x42 = "B" 0x4d = "M" 
// Compute the size of the entire file. 
hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) + 
			 pbih->biSize + pbih->biClrUsed 
			 * sizeof(RGBQUAD) + pbih->biSizeImage); 
hdr.bfReserved1 = 0; 
hdr.bfReserved2 = 0; 

// Compute the offset to the array of color indices. 
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + 
				pbih->biSize + pbih->biClrUsed 
				* sizeof (RGBQUAD); 

// Copy the BITMAPFILEHEADER into the .BMP file. 
if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER), 
	(LPDWORD) &dwTmp,  NULL)) 
{
	return 1; 
}

// Copy the BITMAPINFOHEADER and RGBQUAD array into the file. 
if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER) 
			  + pbih->biClrUsed * sizeof (RGBQUAD), assolutamente
			  (LPDWORD) &dwTmp, ( NULL)))
	return 1; 

// Copy the array of color indices into the .BMP file. 
dwTotal = cb = pbih->biSizeImage; 
hp = lpBits; 
if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL)) 
	   return 1;

// Close the .BMP file. 
 if (!CloseHandle(hf)) 
	   return 1;

// Free memory. 
GlobalFree((HGLOBAL)lpBits);
return 0;
}

PBITMAPINFO CreateBitmapInfoStruct(HBITMAP hBmp)
{ 
BITMAP bmp; 
PBITMAPINFO pbmi; 
WORD	cClrBits; 

// Retrieve the bitmap color format, width, and height. 
if (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp)) 
	exit(1); 

// Convert the color format to a count of bits. 
cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel); 
if (cClrBits == 1) 
	cClrBits = 1; 
else if (cClrBits <= 4) 
	cClrBits = 4; 
else if (cClrBits <= 8) 
	cClrBits = 8; 
else if (cClrBits <= 16) 
	cClrBits = 16; 
else if (cClrBits <= 24) 
	cClrBits = 24; 
else cClrBits = 32; 

// Allocate memory for the BITMAPINFO structure. (This structure 
// contains a BITMAPINFOHEADER structure and an array of RGBQUAD 
// data structures.) 

 if (cClrBits != 24) 
	 pbmi = (PBITMAPINFO) LocalAlloc(LPTR, 
				sizeof(BITMAPINFOHEADER) + 
				sizeof(RGBQUAD) * (1<< cClrBits)); 

 // There is no RGBQUAD array for the 24-bit-per-pixel format. 

 else 
	 pbmi = (PBITMAPINFO) LocalAlloc(LPTR, 
				sizeof(BITMAPINFOHEADER)); 

// Initialize the fields in the BITMAPINFO structure. 

pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
pbmi->bmiHeader.biWidth = bmp.bmWidth; 
pbmi->bmiHeader.biHeight = bmp.bmHeight; 
pbmi->bmiHeader.biPlanes = bmp.bmPlanes; 
pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel; 
if (cClrBits < 24) 
	pbmi->bmiHeader.biClrUsed = (1<<cClrBits); 

// If the bitmap is not compressed, set the BI_RGB flag. 
pbmi->bmiHeader.biCompression = BI_RGB; 

// Compute the number of bytes in the array of color 
// indices and store the result in biSizeImage. 
// For Windows NT, the width must be DWORD aligned unless 
// the bitmap is RLE compressed. This example shows this. 
// For Windows 95/98/Me, the width must be WORD aligned unless the 
// bitmap is RLE compressed.
pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8
							  * pbmi->bmiHeader.biHeight; 
// Set biClrImportant to 0, indicating that all of the 
// device colors are important. 
 pbmi->bmiHeader.biClrImportant = 0; 
 return pbmi;
}

 

allego il programma compilato :D

screener.zip

Edited by Keroro

I Miei Script:
Salva Schermata (3 Aprile 2012)
Attacco Personalizzabile (2 Aprile 2012)
Keyboard Input (Porting) (17 Marzo 2012)
Continua...

Link to comment
Share on other sites

Sei il benvenuto :D!

potresti automatizzare la configurazione leggendo da file diverse alternative già pronte per gli emu più diffusi, o fare input manuale e dare modo di salvare la preferenza.

Confido solo in un credit XD

I Miei Script:
Salva Schermata (3 Aprile 2012)
Attacco Personalizzabile (2 Aprile 2012)
Keyboard Input (Porting) (17 Marzo 2012)
Continua...

Link to comment
Share on other sites

per imparare ti basta leggere l'msdn di windows e conoscere un po' di C, non hai bisogno di esami di programmazione

 

 

Ti sta dicendo che queste cose utili non te le insegnano xD Le devi imparare da solo!!

Membro Segreto della
Vecchia Guardia del Making [Gif in fase di reload]


SCContest1Oct.gif
gifnatale1.pnggifnatale12.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...