Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Strange Image IO

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Strange Image IO

    I am testing the code for a 4X4 gif image named abc which I made with MSpaint which contained 2 black pixels and rest as white
    Once I ran the code (given below) the output was
    -1 -1 -1 -1
    -1 -1 -16777216 -1
    -1 -1 -1 -1
    -16777216 -1 -1 -1

    I compiled and ran the same program again now output is

    -1 -1 -1 -16777216
    -1 -1 -1 -16777216
    -1 -1 -1 -16777216
    -16777216 -1 -1 -16777216

    Isn't this strange because my program reads and doesn't modify any pixel data?

    After the first run the image is unmodified in MS Paint also
    but after the second run the modification is visible in MS Paint also

    How can I prevent this from happening?
    Is something wrong with my output code?

    public static void main(String args[])throws Exception
    {
    BufferedImage img;
    File ptr =new File("abc.gif");
    img = ImageIO.read(ptr);
     
    int height=img.getHeight();
    int width=img.getWidth();
     
    int rgb;
     
    for(int i=0;i<width;i++)
    {
    for(int j=0;j<height;j++)
    {
    rgb =img.getRGB(i,j);
    System.out.print(rgb+" ");
    }
    System.out.print("\n");
    }
     
    ImageIO.write(img,"gif",ptr);
    }
    Last edited by helloworld922; June 14th, 2013 at 12:38 PM. Reason: please use [code] tags


  2. #2
    Junior Member
    Join Date
    Jun 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Strange Image IO

    Anyone help please?

Similar Threads

  1. strange for-loop what is it doing?
    By kaskoepoes112 in forum Loops & Control Statements
    Replies: 6
    Last Post: February 20th, 2013, 01:52 AM
  2. Please help this is strange.
    By MillerJLee79 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 7th, 2012, 03:01 AM
  3. Strange boxes appearing
    By fishnj1333 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 11th, 2012, 05:36 AM
  4. something strange
    By frozen java in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 4th, 2011, 07:58 PM
  5. Strange Compiling Error
    By crism85 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 13th, 2009, 12:59 AM