a long time back I found some ruby that did this, but it didnt work quite correctly.
 
Marco Brasse recently sent an update. Its below. I think it only does bitmap.
 
 
 
require 'dl/import'

module ScreenCapture
  extend DL::Importable

  dlload "kernel32.dll","user32.dll","gdi32.dll"

  HORZRES = 8
  VERTRES = 10
  SRCCOPY = 0xCC0020
  GMEM_FIXED = 0
  GMEM_MOVEABLE = 0x0002
  DIB_RGB_COLORS = 0
  GHND = 0x40
  GPTR = 0x42

  typealias "HDC","unsigned long"
  typealias "HBITMAP","unsigned long"

  extern "HDC GetWindowDC(int)"
  extern "HDC CreateCompatibleDC(HDC)"
  extern "int GetDeviceCaps(HDC, int)"
  extern "HBITMAP CreateCompatibleBitmap(HDC, int, int)"
  extern "long SelectObject(HDC, HBITMAP)"
  extern "long BitBlt(HDC, long, long, long, long, HDC, long, long,
long)"
  extern "void* GlobalAlloc(long, long)"
  extern "void* GlobalLock(void*)"
  extern "long GetDIBits(HDC, HBITMAP, long, long, void*, void*, long)"
  extern "long GlobalUnlock(void*)"
  extern "long GlobalFree(void*)"
  extern "long DeleteObject(unsigned long)"
  extern "long DeleteDC(HDC)"
  extern "long ReleaseDC(long, HDC)"

  module_function
  def screenCapture(filename = "tmp.bmp")
    hScreenDC = getWindowDC(0)
    hmemDC = createCompatibleDC(hScreenDC)
    screenWidth = getDeviceCaps(hScreenDC, HORZRES)
    screenHeight = getDeviceCaps(hScreenDC, VERTRES)
    hmemBM = createCompatibleBitmap(hScreenDC, screenWidth,
screenHeight)
    selectObject(hmemDC, hmemBM)

    printf("width,height = #{screenWidth},#{screenHeight}\n")

    r = bitBlt(hmemDC, 0, 0, screenWidth, screenHeight, hScreenDC, 0, 0,
SRCCOPY)
    printf("bitBlt : #{r}\n")

    hpxldata = globalAlloc(GMEM_FIXED, screenWidth * screenHeight * 3)
    lpvpxldata = globalLock(hpxldata)

    bmInfo = [
      40, screenWidth, screenHeight, 1, 24,
      0, 0, 0, 0, 0, 0, 0].pack('LLLSSLLLLLL').to_ptr
    bmFileHeader = [
      19778, (screenWidth * screenHeight * 3) + 40 + 14,
      0, 0, 54].pack('ILIIL').to_ptr

    r = getDIBits(hmemDC, hmemBM, 0, screenHeight,
  lpvpxldata, bmInfo, DIB_RGB_COLORS)
    printf("getDIBits : #{r}\n")

    File::open(filename, "wb") { |bitmap|
      bitmap.print(bmFileHeader.to_s(14))
      bitmap.print(bmInfo.to_s(40))
      bitmap.print(lpvpxldata.to_s(screenWidth * screenHeight * 3))
    }

    globalUnlock(hpxldata)
    globalFree(hpxldata)
    deleteObject(hmemBM)
    deleteDC(hmemDC)
    releaseDC(0, hScreenDC)
  end
end

ScreenCapture::screenCapture()
 
 
 
 
----- Original Message -----
From: Prem
Sent: Wednesday, September 27, 2006 6:56 PM
Subject: Re: [Wtr-general] Image Capture Package?

You could try out cropper. pretty neat. comes with source code. used by the mantis project as well.

On 9/28/06, Steve Tangsombatvisit < [EMAIL PROTECTED]> wrote:
Hi everyone,

I was just wondering if anyone can recommend a good image capture library/package that can be used with Ruby/Watir? We need to do pretty basic image capture like capture a specific window, or a specific frame within a window and then save the image as a bmp or jpg file.

Thanks in advance,

Steve Tang
 

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general




--
- Prem

  I spent a minute looking at my own code by accident.
  I was thinking "What the hell is this guy doing?"
  ----------------------------------------------------
  Prem Kumar Aparanji
  M: 00919845226618
  [Bangalore, KA, INDIA]

  http://scorpfromhell.blogspot.com


_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to