Save screen bitmap into a file

Javi Domínguez


I want to crop an image from the screen and save it to a file. I have no problem taking the image but I can't save it correctly. I do this but the resulting file looks faulty. Does anyone have an idea what I'm doing wrong?

    bm = screenBitmap.ScreenBitmap(width,height)
    px = bm.captureImage(top,left,width,height)
    data = b''.join([
    # file header
    struct.pack("!H", 0X424D), # file type ID
    struct.pack("I", 0XE+bm._bmInfo.bmiHeader.biSize+bm._bmInfo.bmiHeader.biSizeImage), # file size
    struct.pack("H", 0), # reserved
    struct.pack("H", 0), # reserved
    struct.pack("I", 0XE+bm._bmInfo.bmiHeader.biSize), # Image data start possition
    # bitmap header
    # image data
    with open(r"c:\screenshot.bmp", "wb") as f:

Javi Dominguez

Join to automatically receive all group messages.