Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Angry Problem with displaying an image in Java Swing

    Hi,

    I am writing an application to automate most of the steps for posting an AD on backpage. I am running into the problem of capturing the ReCaptcha graph and then being able to display to the end user.
    Since the image is not of type gif, jpg, or png, the default Image type.

    Can you please suggest what is the best way to implement the solution?

    Thanks in advance.

    AJ

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Well, take a look at the java.awt.Robot class. It has the ability to do a screen capture.

  3. #3
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default

    toadaly,

    I am not looking to screen capture. I can capture the image url something like this...
    http://www.google.com/recaptcha/api/...-vwiKxJZgvQagA
    but what I want is to be able to display this image to end user as a pop-up along with a textbox to enter the "2 words". I hope I am more clear this time.

    Thanks again,
    AJ

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default

    Well, the image appears to be a jpeg. Why not just open a stream to the url, download the bytes to a file - i.e. captcha.jpg and then loading that back into java as a buffered image via ImageIO ?

  5. #5
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default

    You know I tried something to the effect of reading the image as bytes and trying to render it from there... but it didnt work. However I will try to save it as a jpg and see if that will work. I will let you know. Thanks for suggesting this.
    AJ

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default

    You can't just render the bytes. The byte data is jpeg encoded and a BufferedImage is not! Its just a bitmap! When saving the file and reloading it via ImageIO, the jpeg is decoded and you get a decoded bufferedImage object which is a raw bitmap!

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default

    Sorry, lots of !!!! in there. Got excited :D

  8. #8
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default

    So what are you trying to say is that , this solution of saving the bytes as raw image will not work? I am new to the GUI so I am learning. Do you have a possible way to resolve this?

  9. #9
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default

    Sorry, I was trying to say, when you downloaded the bytes into memory and tried to display them directly (I assume by trying to make a raster or supply a buffered image with a byte array or something) it was destined to fail, because the bytes themselves did not represent RGB color values, rather, jpeg encoded regions of an image. The method I proposed (download to a real file, then reload via ImageIO) should work since the jpeg data gets decoded into raw data when ImageIO loads it. Does that make sense?

  10. #10
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default

    Yes, Now it does. Let me try and get back to you. Thanks again.
    AJ

  11. #11
    Join Date
    Jan 2011
    Posts
    6
    Rep Power
    0

    Default

    Hey Quad,
    I just sent you a message. Can you please check if you got it?
    AJ

Similar Threads

  1. Regarding problem with displaying image in jsp
    By sandeepsai39 in forum New To Java
    Replies: 4
    Last Post: 10-04-2010, 04:23 PM
  2. Getting and Displaying Swing Components From DataBase
    By vivekkumar in forum AWT / Swing
    Replies: 1
    Last Post: 07-27-2010, 03:32 PM
  3. Displaying an image
    By SWEngineer in forum AWT / Swing
    Replies: 11
    Last Post: 01-28-2010, 05:48 AM
  4. Replies: 0
    Last Post: 11-07-2009, 06:45 AM
  5. Displaying Chinese characters on Swing components
    By vaskarbasak in forum AWT / Swing
    Replies: 3
    Last Post: 06-26-2008, 08:27 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •