By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Image comments

P: 8
Do you know code for skipping over comments in the header of an image? I'm writing a program to read an image in, modify it, and then shoot out a new image but I can only read certain images that don't have comments in them. Here is the code that I have, but it won't work for some reason.

Expand|Select|Wrap|Line Numbers
  1. public static int getNumber(DataInputStream rd) throws IOException 
  2.         {
  3.         int num;
  4.         int number = 0;
  5.         num= rd.readUnsignedByte();
  6.         while(Character.isWhitespace(num)) 
  7.             {
  8.             num = (char)rd.readUnsignedByte();
  9.             }
  10.         while(num == '#') 
  11.             {
  12.             while(num != '\n') 
  13.                 {
  14.                 num = rd.readUnsignedByte();
  15.                 }
  16.                 // skip white spaces here
  17.             }//to make sure and skip comments
  18.         while(Character.isDigit(num)) 
  19.             {
  20.             number = number * 10 + Character.getNumericValue(num);
  21.             num = rd.readUnsignedByte();
  22.             }
  23.         while(num == '#')
  24.             {
  25.             while(num != '\n') 
  26.                 {
  27.                 num = rd.readUnsignedByte();
  28.                 }
  29.             }//to make sure that no comments were started after skipping them earlier
  30.  
  31.         return number;
  32.         }
  33.  
Thanks!
Dec 5 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.