473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem in saving and loading images using ImageIO

Hey everyone,

I'm working on a program based on steganography. For this, i need to access the individual pixels and perform my manipulations. FYI, I do not have the JAI library available with me and I have to make do with awt, imageIO and image. I'm having no issues in loading an image but when i thought I would test things and just save the same image without manipulation I was surprised. After copying the pixels from the image into an int array, I just created a new image with the same pixel array and image type. When I loaded the new image and compared both their pixels, the array was not the same! Can anyone tell me why this is happening and/or how I can get around this?

Here is some of my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. //In the class ImgStuff
  3. public BufferedImage loadImg(String fileName){
  4. BufferedImage bImg = null;
  5. try {   
  6.  
  7.             bImg = ImageIO.read(new File(fileName)); 
  8.             return bImg;
  9.         } catch (Exception e) {   
  10.             e.printStackTrace(); 
  11.             return null;
  12.         }   
  13.  
  14.     }
  15.  
  16.  
  17. //In function 'main' of  StegoTest.java
  18.  
  19. ImgStuff img = new ImgStuff();
  20. BufferedImage b = img.loadImg("D:/c.jpg");
  21. int pixels[] = new int[b.getWidth()*b.getHeight()];
  22. b.getRGB(0, 0, b.getWidth(), b.getHeight(), pixels, 0, b.getWidth());
  23. BufferedImage b2;
  24. /* b2.setRGB(0, 0, b.getWidth(), b.getHeight(), pixels, 0, b.getWidth()); <-- doesn't work this way either */
  25. File file = new File("D:/done2.jpg");
  26. try{
  27. ImageIO.write(b, "JPEG",file);
  28. }catch(Exception e){
  29. System.out.println(e);
  30. }    
  31. b2 = img.loadImg("D:/done2.jpg");
  32. int pixels2[] = new int[b2.getWidth()*b2.getHeight()];
  33. b2.getRGB(0, 0, b2.getWidth(), b2.getHeight(), pixels2, 0, b2.getWidth());
  34. /*compare the pixel arrays*/
  35. for(int i=0;i<pixels2.length;i++){
  36. if(pixels[i]!=pixels2[i]){
  37. System.out.println("No");
  38. break;
  39. }
  40. }
  41.  
Could really use your help here. I've tried "jpg", "jpeg" and various uppercase combination for the 'format' argument.

Thanks in advance,

Nikhil
Mar 17 '09 #1
0 2013

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

Similar topics

2
by: Clyde Ellul | last post by:
Hi there. I need to write a simple program that reads a GIF image from an input stream, resizes it, then writes it back to an output stream in the same format (GIF). (JPEG input/output is good...
3
by: Aaron Davies | last post by:
I'm trying to write some classes for my collaborative whiteboard to transmit images over the network, using the javax.imageio API, but I'm running into an odd problem: my code words fine with PNGs,...
0
by: Mark McKay | last post by:
I will be starting a contract with a film production company soon, and will be writing code to process large images representing frames of movies (unknown file format at this time). I'd also like...
45
by: Stephen Poley | last post by:
People in these groups, and on web-pages, not infrequently suggest that it is worthwhile cutting down on white-space and comments in HTML and CSS in order to reduce loading times. I and others have...
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
7
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
1
by: ttamilvanan81 | last post by:
Hai everyone, I need to provide the slideshow for the images. I have upload the images into database. Then i will retrive all the images from the database and provide the slideshow for those...
2
ashsa
by: ashsa | last post by:
Hi, Am trying to extract an image from a URL as follows: try { BufferedImage input = ImageIO.read(new URL("http://www.google.co.in/images/close_sm.gif")); File outputFile = new...
2
by: mndprasad | last post by:
hi all i am doing a project in java where i need to convert 10 jpeg images into a single tiff image..conversion of single jpeg image to single tiff is happening but embedding all the 10 jpeg images...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.