Java Swing Question: Robot Screenshot does odd things when close tothe mouse cursor

Discussion in 'Java' started by George Weis, Feb 23, 2010.

  1. George Weis

    George Weis Guest

    Hi:
    I'm trying to write a simple screen enlarger. The basic
    algorithm is this:

    a.) Get current mouse coordinates.
    b.) Take a screen shot using a rectangle consisting of (mouse X,
    mouse Y, 150, 150)
    c.) Create a new scaled image from the screen shot with a height and
    width of 300.
    This should "zoom" 2 X for the portion of the screen the mouse cursor
    is on and show it in a 300 X 300 box
    (the image is drawn on the glass panel on top of the other root
    panels).

    This doesn't produce the result I want.

    The screen shot looks fine if I take the screen shot 350 pixels away
    from the current mouse coordinates, in other words (mouse X + 350,
    mouse Y + 350, 150, 150).

    But, if I try to take the screen shot too close to the current X and
    Y, I get double or triple images of the same area in the image.

    I can't attach a sample image, but it looks like this, each number
    representing one of the images.

    1 | 2 | 3 |
    | | |
    ---- | |
    | |
    -------- --- |
    |
    --------------------

    Anyone know what is causing this behavior? And how to get rid of it?
    And by the way, I freely admit I am a newbie, so if anyone knows a
    better way to render a zoom of an arbitrary part of a User Frame,
    please let me know.

    Thanks,

    George
     
    George Weis, Feb 23, 2010
    #1
    1. Advertising

  2. George Weis

    George Weis Guest

    Re: Java Swing Question: Robot Screenshot does odd things when closeto the mouse cursor

    Makes sense to me. I guess you'd get the same effect by looking at
    two mirrors
    lined up opposite each other.

    As for your words of advice, it just would be nice to something in
    pure java,
    because the product is supposed to be run on a variety of platforms.
    So,
    the alternative is to say:

    if we're on windows
    {
    use maximize.exe
    }
    else if we're on a Mac
    {
    use whatever they use
    }
    else if we're on Mandrake
    ....

    that's pretty ugly too.

    > Right.  If you're old enough, you might remember a common video effect
    > accomplished by pointing the video camera at a monitor showing the image
    > captured by the video camera.  They don't use it much these days, but it
    > was all the rage in the 70's.  :)
    >
    > Anyway, the problem is that you are capturing the image from the screen.
    >   So of course, once you display the updated scaled image on the screen,
    > the next capture includes the scaled image, so that scaled portion is
    > scaled again and presented again.  Every time your code recaptures the
    > display, this occurs and you get a sort of "tunnel vision" effect.
    >
    > Depending on what you're trying to do, it's either simple to fix or not.
    >   If you're trying to implement a completely general "magnifying" tool
    > that will scale arbitrary regions of the computer display, you're in for
    > an uphill battle, especially in Java.  You need more control over the
    > rendering process than simply doing a screen capture, so that when you
    > obtain an image to be scaled, it's the _original_ image, not one that
    > includes your scaling.
    >
    > On the other hand, if you're just trying to scale stuff in your own Java
    > application, that's a lot simpler if you're willing to write a custom
    > component into which the drawing happens.  In your component's paint()
    > method, you can use the transform features of the Graphics instance to
    > scale whatever drawing you do in the component.
    >
    > Even there, you may run into difficulty if you want to scale not only
    > your own drawing, but also how built-in Java components draw.  It's
    > possible for lightweight controls you might be able to intercept the
    > rendering process early enough to scale the output, but for controls
    > that are based on platform/OS, forcing those to scale will be trickier,
    > if possible at all.
    >
    > Pete
     
    George Weis, Feb 23, 2010
    #2
    1. Advertising

  3. Re: Java Swing Question: Robot Screenshot does odd things when close to the mouse cursor

    In article
    <>,
    George Weis <> wrote:

    > Hi:
    > I'm trying to write a simple screen enlarger. The basic
    > algorithm is this:
    >
    > a.) Get current mouse coordinates.
    > b.) Take a screen shot using a rectangle consisting of (mouse X,
    > mouse Y, 150, 150)
    > c.) Create a new scaled image from the screen shot with a height and
    > width of 300.
    > This should "zoom" 2 X for the portion of the screen the mouse cursor
    > is on and show it in a 300 X 300 box (the image is drawn on the glass
    > panel on top of the other root panels).
    >
    > This doesn't produce the result I want.
    >
    > The screen shot looks fine if I take the screen shot 350 pixels away
    > from the current mouse coordinates, in other words (mouse X + 350,
    > mouse Y + 350, 150, 150).
    > ...
    > Anyone know what is causing this behavior? And how to get rid of it?
    > And by the way, I freely admit I am a newbie, so if anyone knows a
    > better way to render a zoom of an arbitrary part of a User Frame,
    > please let me know.


    I think Pete's right about the "video feedback" effect. Here's an
    alternate way to get a BufferedImage of a component that can be scaled
    _ad_lib_. On the downside, the image will be "pixelated," accordingly.

    <http://groups.google.com/group/comp.lang.java.gui/msg/662e54ff77c3e6f8>

    You can get a smoother result by adjusting the graphics context's
    transform. Here's an example that scales to fill the enclosing panel

    <http://groups.google.com/group/comp.lang.java.gui/msg/3f1781d063cae9e7>

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
     
    John B. Matthews, Feb 23, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    528
  2. tom arnall
    Replies:
    6
    Views:
    1,292
    Ian Shef
    Jan 18, 2007
  3. Weng Tianxiang
    Replies:
    7
    Views:
    1,321
    Paul Uiterlinden
    Sep 11, 2009
  4. dmaziuk
    Replies:
    3
    Views:
    594
    Chris Gonnerman
    Jan 25, 2011
  5. Iñaki Baz Castillo
    Replies:
    7
    Views:
    895
    Iñaki Baz Castillo
    Jan 12, 2010
Loading...

Share This Page