• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Capturing ScreenShot of the the Active Window

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I am working on a simple application to capture the screen shot of the entire screen and save it in a Disk File. This is what the screen capturing code looks like :



Now i need to add a feature that would capture the screen shot of only the Active Window (& not the entire screen).

Do we have such APIs in java, which my application can use directly ? If not, what could be the ways in which this can be implemented ?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would think that the way to do it is to pass the rectangle of the currently active window to the createScreenCapture method, instead of the rectangle of the full screen.
 
Parth Bhatt
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly Ulf... but is there a way to get the rectangle of the active window.

Specifically, do we have APIs provided by either jdk or other lib that would return the rectangle for the active window...?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that we're talking about a Java window, look at the getLocationOnScreen method. In conjunction with the getWidth and getHeight methods it should give you the necessary data. The getBounds method may also be helpful.
 
Parth Bhatt
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, for being a little less specific...

Actually, I was referring to the OpenSource project that i started :
GNUSnap

It Presents a very simple GUI that lets the user to capture the screen shot(for now, the snap shot is only of the complete screen) @ the click of a button.

What i wish to add to this is that the user can set an appropriate timeout(say of n secs) and click the button to take the screen shot. After n seconds my app would capture the shot of the Window that is the Active Window(this need not be a window launched my My App, it could be any window belonging to any process in the system).

For Example : Assume i am using Windows. I could configure my app to take a snap shot of the Active Window after 5 secs, minimize the app and launch Notepad. After 5 secs My App would take the snapshot of Notepad(and not the whole screen).

Similarly, if i am on Linux, i would be able to do the same.

If anyone has any idea regarding this, please put it forth...
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic