donation of BMP writing code
Displaying 1-6 of 6 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
geronimo

i figured i'd donate this vc routine i wrote to grab frames from my thing:


int ScreenShot_Number;
void SaveScreenShot()
{
string ScreenShot_Filename;
int file;
int row, col;
int something;

ScreenShot_Filename="screens\"+str(ScreenShot_Number)+".bmp";
file=FileOpen(ScreenShot_Filename,FILE_WRITE);

FileWrite(file,"BM");
FileWriteQuad(file,0); // file size (ignore)
FileWriteQuad(file,0); // two reserved words
FileWriteQuad(file,54); // offset to image data

FileWriteQuad(file,40); // size of the bitmap info structure
FileWriteQuad(file,320); // image width
FileWriteQuad(file,240); // image height
FileWriteWord(file,1); // Number of planes? *shrug*
FileWriteWord(file,24); // bits per pixel
FileWriteQuad(file,0); // no compression
FileWriteQuad(file,0); // size of bitmap data (ignore)
FileWriteQuad(file,0); // whatever, man
FileWriteQuad(file,0); // whatever, man...
FileWriteQuad(file,0); // number of colors (ignore)
FileWriteQuad(file,0); // important colors (ignore)

for(row=239;row>=0;row--)
{
for(col=0;col<320;col++)
{
something=GetPixel(col,row,screen);
FileWriteByte(file,GetB(something));
FileWriteByte(file,GetG(something));
FileWriteByte(file,GetR(something));
}

}

FileClose(file);
ScreenShot_Number++;
}

Posted on 2004-04-27 20:38:09 (last edited on 2004-04-27 20:39:11)

mcgrue

That's way awesome. I think you need to create the screens directory yourself, but I removed that bit to test and it worked fine : )

Posted on 2004-04-27 21:03:45

rpgking

NICE. This'll come in real handy.

Posted on 2004-04-27 23:17:52

el_desconocido

That is sweet. And if you are curious:

X/YPelsPerMeter specifies the horizontal/vertical resolution, in pixels per meter, of the target device for the bitmap. An application can use this value to select a bitmap from a resource group that best matches the characteristics of the current device.

But like you said, whatever, man...

El

Posted on 2004-04-28 02:46:56

RageCage

truely 1337 code, I applaud you

Posted on 2004-04-28 03:25:30

Buckermann

Great function!
However, I took the liberty to expand it a bit.
First, the last screenshot number will be stored in a text file called "Scnr.txt" (you have to create this file yourself in your screens directory and just write a "0" (zero) at the beginning). This way the screenshots can't be overwritten. The ResetScreenShotIndex() function will just write a zero into the Scnr.txt file so the numbering will start at "0000" again.
Second, I added some leading zeros to the screenshot number. Just to keep the screenshots in a proper order.


void SaveScreenShot2()
{
//get the last screenshot number
int SSIndex = FileOpen("screens/scnr.txt",1);
int ScreenShot_Number = val(FileReadString(SSIndex));
FileClose(SSIndex);
string SSString_Number = str(ScreenShot_Number);
//add some leading zeros if needed
if (ScreenShot_Number < 10)
SSString_Number = "000"+SSString_Number;
if (ScreenShot_Number > 9 && ScreenShot_Number < 100)
SSString_Number = "00"+SSString_Number;
if (ScreenShot_Number > 99 && ScreenShot_Number < 999)
SSString_Number = "0"+SSString_Number;

int ScreenHandler = screen;
int SSX = ImageWidth(ScreenHandler);
int SSY = ImageHeight(ScreenHandler);
string ScreenShot_Filename="screens\ScreenShot_"+SSString_Number+".bmp";
int file;
int row, col;
int something;
Log("Save Screenshot : "+ScreenShot_Filename);

file=FileOpen(ScreenShot_Filename,FILE_WRITE);

FileWrite(file,"BM");
FileWriteQuad(file,0); // file size (ignore)
FileWriteQuad(file,0); // two reserved words
FileWriteQuad(file,54); // offset to image data
FileWriteQuad(file,40); // size of the bitmap info structure
FileWriteQuad(file,SSX); // image width
FileWriteQuad(file,SSY); // image height
FileWriteWord(file,1); // Number of planes? *shrug*
FileWriteWord(file,24); // bits per pixel
FileWriteQuad(file,0); // no compression
FileWriteQuad(file,0); // size of bitmap data (ignore)
FileWriteQuad(file,0); // whatever, man
FileWriteQuad(file,0); // whatever, man...
FileWriteQuad(file,0); // number of colors (ignore)
FileWriteQuad(file,0); // important colors (ignore)

for(row=SSY-1;row>=0;row--)
{
for(col=0;col<SSX;col++)
{
something=GetPixel(col,row,ScreenHandler);
FileWriteByte(file,GetB(something));
FileWriteByte(file,GetG(something));
FileWriteByte(file,GetR(something));
}
}
FileClose(file);
ScreenShot_Number++;
SSIndex = FileOpen("screens/scnr.txt",2);
FileWriteString(SSIndex, str(ScreenShot_Number));
FileClose(SSIndex);
MessageBox("Screenshot saved");
}

void ResetScreenShotIndex()
{
int SSIndex = FileOpen("screens/scnr.txt",2);
FileWriteString(SSIndex, "0");
FileClose(SSIndex);
}

Posted on 2004-04-29 17:14:15


Displaying 1-6 of 6 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.