Results 1 to 7 of 7
  1. #1
    kosmos890 is offline Member
    Join Date
    Apr 2012
    Posts
    40
    Rep Power
    0

    Default How to get image encoding?

    This code works on Linux but on Windows xp Iterator<ImageReader> readers is empty. (java 7)
    How can I fix this problem?

    Are there other ways to detect file encoding?
    Java Code:
    public static void main(String[] args) {
    
            URL url = null;
    
            try {
                url = new URL("http://www.java-forums.org/content/");
            } catch (MalformedURLException ex) {
                Logger.getLogger(ImageDemo.class.getName()).log(Level.SEVERE, null, ex);
            }
            ImageInputStream input = null;
    
            try {
                input = ImageIO.createImageInputStream(url.openStream());
            } catch (IOException ex) {
                Logger.getLogger(ImageDemo.class.getName()).log(Level.SEVERE, null, ex);
            }
    
            //readers is empty
            Iterator<ImageReader> readers = ImageIO.getImageReaders(input);
    
            while (readers.hasNext()) {
                ImageReader read = readers.next();
                try {
                    String formatName = read.getFormatName();
                    System.out.println("Format name : "+formatName);
                    
                } catch (IOException ex) {
                    Logger.getLogger(ImageDemo.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: How to get image encoding?

    Is 'input' null?
    What image are you trying to load?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    kosmos890 is offline Member
    Join Date
    Apr 2012
    Posts
    40
    Rep Power
    0

    Default Re: How to get image encoding?

    @Tolls
    Thanks for your reply
    Is 'input' null?
    What image are you trying to load?
    Sorry. It 's my mistake. I change URL.
    Java Code:
    url = new URL("http://www.java-forums.org/favicon.ico");
    I want to get the favicon of a web-page and I want to detect favicon's encoding (ico or png).
    The favicon's source-location is right. (Sorry for my bad english)
    I find the supported image format:
    Java Code:
    String[] types = ImageIO.getReaderFormatNames();
    But as I said Iterator<ImageReader> readers is always empty.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: How to get image encoding?

    As I asked, though, is 'input' null after this:
    Java Code:
    input = ImageIO.createImageInputStream(url.openStream());
    ?
    Because if it is then your system is having problems identifying the image as something it can understand.
    That line there does not just create an input stream to the image. It *only* creates an input stream to the image if it's a type it recognises, at least that's how I read the API.
    "
    The set of ImageInputStreamSpis registered with the IIORegistry class is queried and the first one that is able to take input from the supplied object is used to create the returned ImageInputStream. If no suitable ImageInputStreamSpi exists, null is returned.
    "
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    kosmos890 is offline Member
    Join Date
    Apr 2012
    Posts
    40
    Rep Power
    0

    Default Re: How to get image encoding?

    @Tolls
    Thanks for your reply
    It *only* creates an input stream to the image if it's a type it recognises
    Input is not null so system recognises image type. But Iterator<ImageReader> readers is empty.
    Here someone describes the same problem.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: How to get image encoding?

    OK, so all you can do is try and follow that advice (or the one in the linked post).
    You could try and simply save the image, then attempt to open it using ImageIO.read().
    At least until you manage to figure out the problem.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    kosmos890 is offline Member
    Join Date
    Apr 2012
    Posts
    40
    Rep Power
    0

    Default Re: How to get image encoding?

    @Tolls thanks for your reply

    I have this problem with java 7. (I try java 7u17 and java 7u21)
    Finally I decide to use java 6u43 and the code works fine.

Similar Threads

  1. Url encoding
    By RaviGupta0709 in forum Web Frameworks
    Replies: 0
    Last Post: 08-23-2011, 08:02 AM
  2. Need encoding for Korean
    By RamaNalayini in forum Advanced Java
    Replies: 1
    Last Post: 11-25-2010, 02:34 PM
  3. problem in encoding
    By jaysh in forum NetBeans
    Replies: 0
    Last Post: 08-26-2010, 08:07 AM
  4. Encoding Problem
    By GJ! in forum Advanced Java
    Replies: 6
    Last Post: 01-12-2010, 08:09 PM
  5. Some help with encoding...
    By nm123 in forum Networking
    Replies: 0
    Last Post: 04-15-2008, 12:22 AM

Posting Permissions

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