Talk About Network

Google





Graphics > OpenGL 3D API > Re: Modify scre...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 11 Topic 4774 of 5061
Post > Topic >>

Re: Modify screen pixels

by navid_ad <navid.fallah@[EMAIL PROTECTED] > Jun 15, 2008 at 02:56 PM

Here is the complete program to capture a screenshot, save it to a
file, make some changes(draw a red line), and show it on screen.

#include "iostream"
#include "windows.h"
#include "time.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <io.h>

using namespace std;

int main() {
        HDC hScreenDC = GetDC(NULL);//GetWindowDC(0);
        HDC hmemDC = CreateCompatibleDC(hScreenDC);

        int ScreenWidth = GetDeviceCaps(hScreenDC, HORZRES);
        int ScreenHeight = GetDeviceCaps(hScreenDC, VERTRES);

        BITMAPINFO bmInfo;
        bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
        bmInfo.bmiHeader.biWidth = ScreenWidth;
        bmInfo.bmiHeader.biHeight = -ScreenHeight;
        bmInfo.bmiHeader.biPlanes = 1;
        bmInfo.bmiHeader.biBitCount = 24;
        bmInfo.bmiHeader.biCompression = BI_RGB;
        bmInfo.bmiHeader.biSizeImage = 0;
        bmInfo.bmiHeader.biXPelsPerMeter = 0;
        bmInfo.bmiHeader.biYPelsPerMeter = 0;
        bmInfo.bmiHeader.biClrUsed = 0;
        bmInfo.bmiHeader.biClrIm****tant = 0;

        HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC,
ScreenWidth,
ScreenHeight);//CreateDIBSection(hScreenDC, &bmInfo, DIB_RGB_COLORS,
0, 0, 0);

        BYTE *pbyteBuff = new BYTE[ScreenWidth * ScreenHeight * 3];

        HBITMAP oldbits = (HBITMAP)SelectObject(hmemDC, hBitmap);

        cout<<"aaaaaaaaa"<<endl;

        // copy screen to memory DC
        BitBlt(hmemDC, 0, 0, ScreenWidth, ScreenHeight, hScreenDC, 0,
0,
SRCCOPY);

        // copy bitmap data into global memory
        GetDIBits(hScreenDC, hBitmap, 0, ScreenHeight, pbyteBuff,
&bmInfo,
DIB_RGB_COLORS);

        for(int i = 0; i < ScreenWidth; i++)
                for(int k = 0; k < 20; k++) {
                        pbyteBuff[((200 + k) * ScreenWidth + i) * 3 +
0] = 0;
                        pbyteBuff[((200 + k) * ScreenWidth + i) * 3 +
1] = 0;
                        pbyteBuff[((200 + k) * ScreenWidth + i) * 3 +
2] = 255;
        }

        cout<<"bbbbbbbbb"<<endl;
        char a;
        cin>>a;
        SetDIBitsToDevice(hScreenDC, 0, 0, ScreenWidth, ScreenHeight,
0, 0,
0, ScreenHeight, pbyteBuff, &bmInfo, DIB_RGB_COLORS);
        cin>>a;

        char filename[] = "testScreen01.bmp";

        BITMAPFILEHEADER bmFileHeader;
        bmFileHeader.bfType = 19778;
        bmFileHeader.bfSize = (ScreenWidth * ScreenHeight * 3) +
sizeof(BITMAPINFOHEADER) + 14;
        bmFileHeader.bfReserved1 = 0;
        bmFileHeader.bfReserved2 = 0;
        bmFileHeader.bfOffBits = 54;
        // open file and write data
        int bmfile = open(filename, O_WRONLY | O_CREAT | O_TRUNC |
O_BINARY,
S_IWRITE);
        write(bmfile, &bmFileHeader, 14);
        write(bmfile, &bmInfo, 40);
        write(bmfile, pbyteBuff, ScreenWidth * ScreenHeight * 3);

        // clean up
        delete []pbyteBuff;
        close(bmfile);
        DeleteObject(hBitmap);
        DeleteDC(hmemDC);
        ReleaseDC(0, hScreenDC);

        return 0;
}
 




 11 Posts in Topic:
Modify screen pixels
navid_ad <navid.fallah  2008-06-02 15:42:44 
Re: Modify screen pixels
"jbwest" <jb  2008-06-02 19:19:43 
Re: Modify screen pixels
Jonno <jonno@[EMAIL PR  2008-06-03 08:59:21 
Re: Modify screen pixels
fungus <openglMYSOCKS@  2008-06-03 01:23:27 
Re: Modify screen pixels
"jbwest" <jb  2008-06-03 17:55:10 
Re: Modify screen pixels
navid_ad <navid.fallah  2008-06-10 10:14:40 
Re: Modify screen pixels
aku ankka <jukka@[EMAI  2008-06-11 02:07:37 
Re: Modify screen pixels
navid_ad <navid.fallah  2008-06-11 17:00:18 
Re: Modify screen pixels
navid_ad <navid.fallah  2008-06-11 17:00:28 
Re: Modify screen pixels
navid_ad <navid.fallah  2008-06-15 14:56:20 
Re: Modify screen pixels
Paul Geisler <paul.gei  2008-06-27 02:16:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Fri Jan 9 16:56:25 PST 2009.