Results 1 to 5 of 5
  1. #1
    stegano is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default Error with ImageIO

    This is my code for encryption and to load image. i got this error while compiling

    ImageIO.write(images, "png", bin);




    XML Code:
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.swing.*;
    
    public class encrypt{
    public static void main(String[] args) throws IOException{
    
       
    
    		Scanner input = new Scanner(System.in);
    
    		System.out.println ("Enter Message: ");
    		String msg = input.nextLine();
    
    
    		System.out.println ("Enter Key: ");
    		String key = input.nextLine();
    	
    
    
    
    		byte[] bytes2 = msg.getBytes();
      		StringBuilder binary2 = new StringBuilder();
      		for (byte b : bytes2) {
         			int val = b;
         			for (int i = 0; i < 8; i++) {
            		binary2.append((val & 128) == 0 ? 0 : 1);
            		val <<= 1;
         		}
         		
      	}
    	
    	
    		if(key.length() == 25){
    
      		byte[] bytes = key.getBytes();
      		StringBuilder binary = new StringBuilder();
      		for (byte b : bytes) {
         			int val = b;
         			for (int i = 0; i < 8; i++) {
            			binary.append((val & 128) == 0 ? 0 : 1);
            			val <<= 1;
         			}
         			
      		}
    		
    		//initializing the register using binary key
    
    		boolean[] binarykey = new boolean[200];
    		boolean[] ciphertext = new boolean[200];
    		boolean[] binarymsg = new boolean[binary2.length()];
    		
    		//System.out.println("length = "+binary.length());
    
    		String tab = input.nextLine(); // just for tab, doesn't meaning anything
    
    		
    		for (int i=0; i < binary2.length(); i++) {
    			if (binary2.charAt(i) == '1')
    				binarymsg[i] = true;
    			else if (binary2.charAt(i) == '0')
    				binarymsg[i] = false;
    		}
    
    
    		for (int i=0; i < binary.length();i++) { //the register will run based on length of key
    	 			
    			if (binary.charAt(i) == '1')
    				binarykey[i] = true;
    			else if (binary.charAt(i) == '0')
    				binarykey[i] = false;
    
    
    		}
    		
    		System.out.print("cipher = ");
    		for (int i = 0; i < binary2.length(); i++) {
    
    		    // the tap use to XOR the binary
            	    boolean bit = binarykey[199] ^ binarykey[173] ^ binarykey[149] ^ binarykey[124] ^ binarykey[98] ^ 
    
    binarykey[73] ^ binarykey[49] ^ binarykey[24];
    		   
    			 ciphertext[i] = binarykey[199] ^ binarymsg[i];	
    			
    
    			if (ciphertext[i] == true)
    				System.out.print('1');
    			else if(ciphertext[i] == false)
    				System.out.print('0');
    			
    	    	   
    	        }
    System.out.println("");
    System.out.println("");
    
    
    
    }
    
    
    
    
     
    else
    {
    
    System.out.println();
    System.out.println("you have reached the length limit of the key");
    System.out.println("Please enter key not exceed 25 Characters");	
    }
    	
    File images = new File("tux.png");
    BufferedImage image = ImageIO.read(images);
    
    
    
        ByteArrayOutputStream bin = new ByteArrayOutputStream();
        ImageIO.write(images, "png", bin);
    
    
        byte[] pngByteArray = bin.toByteArray();
    
         
        StringBuilder sb = new StringBuilder();
        for (byte by : pngByteArray)
            sb.append(Integer.toBinaryString(by & 0xFF));
    
        System.out.println(sb.toString());
    
    
    
    }
    	
    	
    }
    Anyone can help????

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    what was the error message?

  3. #3
    stegano is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default

    encrypt.java:128: cannot find symbol
    symbol : method write(java.io.File,jav
    location: class javax.imageio.ImageIO

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    it means the method 'write' doesn't exist, or maybe it does but you used it with incorrect parameters so Java didn't recognise the method signature.

    Java Code:
    ImageIO.write(images, "png", bin);
    Java Code:
    static boolean write(RenderedImage im, String formatName, File output) 
              Writes an image using an arbitrary ImageWriter that supports the given format to a File. 
    static boolean write(RenderedImage im, String formatName, ImageOutputStream output) 
              Writes an image using the an arbitrary ImageWriter that supports the given format to
              an ImageOutputStream. 
    static boolean write(RenderedImage im, String formatName, OutputStream output) 
              Writes an image using an arbitrary ImageWriter that supports the given format to an OutputStream.

  5. #5
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    your variable 'images' is of the type java.io.File, but what you need is a RenderedImage type

Similar Threads

  1. ImageIO doesn't correctly read some standard JPG Files
    By francojava1 in forum Advanced Java
    Replies: 2
    Last Post: 10-18-2010, 05:33 PM
  2. BufferedImage, ImageIO and Jar files
    By satory in forum New To Java
    Replies: 6
    Last Post: 05-23-2010, 01:07 AM
  3. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  4. Trouble with ImageIO
    By sari in forum New To Java
    Replies: 1
    Last Post: 03-30-2009, 10:42 PM
  5. Help with ImageIO
    By romina in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 06:21 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
  •