How to Capture a Part of a Screen Using Ruby on Windows

How to capture a part of a screen using Ruby on Windows?

I haven't tried it (I'm not on windows). But you could use Win32::Screenshot.

While looking around, I've found the following, which does the screenshot using that library

width, height, bitmap = Win32::Screenshot.desktop
img_lst = ImageList.new
img_lst.from_blob(bitmap)
img_lst.write('public/screen.png')

And should write your screenshot as a png file.

How do I capture the screen using Ruby?

I figured out how to do this so I though I would post the solution for others who may need help.

The GetDIBits Win32API function can be used to access the RGB array stored in the bitmap captured using the above code.

http://msdn.microsoft.com/en-us/library/dd144879%28v=vs.85%29.aspx

How to capture a window screen shot in Ruby

Actually we have a library for screenshot in win32 we can make use of that library in order to solve this problem.
Here is the piece of code that might help you

require 'win32/screenshot'
Win32::Screenshot::Take.of(:foreground).write("Screenshot.png")

How to use Win32's BitBlt using Ruby?

Second Carl's other post: use win32 screenshot http://github.com/jarmo/win32screenshot

Capture screenshots for a Ruby on Rails application

I use IMGKit gem for that: https://github.com/csquared/IMGKit

Related topic: How to respond_to PNG or JPG in Rails and generate image from HTML?

How to use Ruby to detect whether on Windows Platform, the SHIFT or ALT key is being pressed?

On Win32, how to detect whether a Left Shift or Right ALT is pressed using Perl, Python, or Ruby (or C)? has some clues...

ruby ffi might help, too



Related Topics



Leave a reply



Submit