Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

579
Views
Ruby Gosu: how can I save the actual Window/Screen in an image file?

I am trying make a screenshot functionality of the actual state of the Window/Screen. How can I achieve this using Ruby Gosu?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use Gosu's Gosu.render method

require "gosu"

class Window < Gosu::Window
  def initialize(*args)
    super
  end
  
  def draw
    Gosu.draw_rect(100, 100, 100, 100, Gosu::Color::YELLOW)
  end
  
  def button_down(id)
    render("screenshot.png") if id == Gosu::KB_F12
  end
  
  def render(filename)
    Gosu.render(600, 600, retro: false) do
      # Put drawing code here, i.e.
      draw
    end.save(filename)
  end
end

Window.new(600, 600, false).show

You also can use Gosu.render without a window if that is desired:

require "gosu"

image = Gosu.render(600, 600, retro: false) do
  Gosu.draw_rect(100, 100, 100, 100, Gosu::Color::YELLOW)
end

image.save("image.png")
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!