Advertisement

Saving the screen in picture format with VB

Started by October 25, 2001 05:42 AM
1 comment, last by Zellam 23 years, 4 months ago
How do to save in a BMP, JPG or GIF format, the screen with VB6 ? Thanks for the help ! N.Zell
I did this once but with VB6.

Basically what I did was:

1. locked the surface that I wanted to save
2. copied the pixels into another array
3. unlocked the surface (not sure if i did this last or not)
4. reorganised the array to the proper BMP format
5. saved as BMP

You have to know the BMP file structure and I remember having some problems locking and unlocking the surface and copying the array. I had to run in 32 bits when I did this.

I´m sure this can be done much more efficiently but I thought I´d give you some basic hints.

Don´t know how the Jpg or Gif fomat is though.
Advertisement
Anyone who has been reading my posts on here will know that my roots lye in VB ;-)

Ok the first thing I will suggest is - USE DEVIL!!! Formerly known as OpenIL - the link is on the NeHe front page - download the latest version and you will have VB support for loading just about any image type under the sun and for use under DX, OGL and W32GDI!!! At the same time, you will also have support for saving as just about any image type under the sun, custom image types, and all with a very simple OGL-a-like interface!!! This makes taking screenshots a breeze (I believe there''s a function built into the library)!!! And it''s open source!!!

Ok enough with the plug *g* I just like DevIL a lot, and I dont think the library is given enough credit to be honest!

The thing you have basically got to do is first define a 1D array which is big enough to hold the entire contents of the frame buffer. Use glCopyPixels (Passing the first element in the array(buffer(0))) to copy the pixel data into the array. Then, reverse the array because (As we all know) VB does some mad shit with arrays. So if the array is 10 elements big, item 0 goes into item 10 and item 10 goes into item 0, 1 into 9, 9 into 1 etc...

Ok great. Now you need to find out the file formats for bmp jpg and gif. Go to www.wotzit.org for sum meja inf. on file formats. I think you will find saving as a JPG an absolute -bitch- and saving as a GIF to be not all that simple. However the BMP file format is easy! Just fill in the header, write it to the file, then write the pixel data to the file - easy peasy!

Hope that helps

This topic is closed to new replies.

Advertisement