Results 1 to 4 of 4
  1. #1
    bmcnamara is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default constructor error in image manipulation app

    hi

    i'm writing a simple image manipulation application for a college assignment, but am getting the following errors:

    Java Code:
    ProjectPhaseII4.java:21: cannot find symbol
    symbol  : constructor File(java.io.File)
    location: class java.io.File
                    inputFile = new File(fileRead);
                                ^
    ProjectPhaseII4.java:97: cannot find symbol
    symbol  : constructor File(java.io.File)
    location: class java.io.File
                                                                    outputFile = new
     File(fileWrite);
                                                                                 ^
    2 errors
    and have no idea why.

    here's my code:
    Java Code:
    import javax.swing.JOptionPane;
    import java.awt.Color;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.io.File;
    import javax.imageio.ImageIO;
    import java.io.IOException;
    
    public class ProjectPhaseII4
    {
    	public static void main (String [] args) throws IOException
    	{
    		String selection, result;
    		String inputFile = args[0], outputFile = args[1];
    		String filePattern = "[a-z 0-9] {1, 16} [a-z 0-9] {1}.jpg", menuOption = "[0-3] {0}";
    		Color existingColour;
    		File fileRead, fileWrite;
    		int imageWidth = 0, imageHeight = 0, alpha = 0;
    		int chioce, newRed = 0, newGreen = 0, newBlue = 0;
    		int oldGreen, oldRed, oldBlue, r, c, averageColour;
    		inputFile = new File(fileRead);
    		BufferedImage storedImage = ImageIO.read(fileRead);
    		imageWidth = storedImage.getWidth();
    		imageHeight = storedImage.getHeight();
    		
    		
    		if (args.length != 2)
    		JOptionPane.showMessageDialog(null, "Please enter input and output filenames", "Error", JOptionPane.ERROR_MESSAGE);
    		else
    		{
    		inputFile = args[0].toLowerCase();
    		outputFile = args[1].toLowerCase();
    			
    		if ((!inputFile.matches(filePattern)) || (!outputFile.matches(filePattern)))
    		JOptionPane.showMessageDialog(null, "Please ensure both filenames are correct format", "Error", JOptionPane.ERROR_MESSAGE);
    			
    			
    			
    					
    		if (!(fileRead.exists()))
    		JOptionPane.showMessageDialog(null, "Input file does not exist", "Error", JOptionPane.ERROR_MESSAGE);
    	        else selection  = JOptionPane.showInputDialog(null, "1. Invert Image" + "\n" + "2 Apply Sepiatone" + "\n" + 
    		"3 Convert Image to Greyscale" + "\n" + "4 Exit");
    		{
    		if (selection !=null || (!selection.matches(menuOption)))
    		JOptionPane.showMessageDialog(null, "Enter numeric data only", "Error", JOptionPane.ERROR_MESSAGE);
    		else
    		{
    		if (selection != null)
    		{
    		int choice = Integer.parseInt(selection);
    										
    		if (choice != 0)
    		{
    		for (r = 0; r < imageHeight; r ++)
    		{
    	        for (c = 0; c < imageWidth; c ++)
    		{
    		alpha = storedImage.getRGB(c ,r);
    		existingColour = new Color(alpha);
    		oldRed = existingColour.getRed();
    		oldBlue = existingColour.getBlue();
    		oldGreen = existingColour.getGreen();
    												
    		if (choice == 1)
    		{
    														
    		newRed = 255 - oldRed;
    		newBlue = 255 - oldBlue;
    		newGreen = 255 - oldGreen;
    		}
    													
    		else if (choice == 2)
    		{
    		newRed = (int) (oldRed * 0.396 + oldGreen * 0.769 + oldBlue * 0.189);
    		newGreen = (int) (oldRed * 0.349 + oldGreen * 0.686 + oldBlue * 0.168);
    		newBlue = (int) (oldRed * 0.272 + oldGreen * 0.534 + oldBlue * 0.131);
    		if (newRed > 255) newRed = 255;
    		if (newBlue > 255) newBlue = 255;
    		if (newGreen > 255) newGreen = 255;		
    		}
    														
    		else if (choice == 3)
    		{
    		newRed = existingColour.getRed();
    		newBlue = existingColour.getBlue();
    		newBlue = existingColour.getGreen();
    		averageColour = (newRed + newGreen + newBlue)/3;
    		newRed = newGreen = newBlue = averageColour;
    		}
    														
    		Color newColour = new Color(newRed, newGreen, newBlue);
    		storedImage.setRGB(c, r, newColour.getRGB());
    		}// inner for
    		}// outer for
    										
    		outputFile = new File(fileWrite);		
    		ImageIO.write(storedImage, "jpg", fileWrite);
    		} // choice not 0
    	        }// end selection not null
    						
    							
    							
    									
    								
    		}
    		}
    			
    	}
    }
    }
    any help would be greatly appreciated.

    regards,
    b.
    Last edited by bmcnamara; 12-05-2009 at 06:24 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You appear to be trying to construct a File using a File variable as a parameter (non-initialized at that), and this doesn't make any sense. What are you trying to do there? What and where is the file that you're trying to initialize?

  3. #3
    bmcnamara is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default

    i'm trying to convert the commad line input string

    Java Code:
    String inputFile = args[0];
    to an image file to be stored in a buffer

    Java Code:
    inputFile = new File(fileRead);
    		BufferedImage storedImage = ImageIO.read(fileRead);
    thanks
    b.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. Image Manipulation
    By sh100 in forum New To Java
    Replies: 0
    Last Post: 11-03-2009, 10:18 AM
  2. Image manipulation
    By spike72 in forum Java 2D
    Replies: 1
    Last Post: 08-28-2009, 08:45 PM
  3. Constructor Error ?
    By sysout in forum New To Java
    Replies: 4
    Last Post: 08-25-2009, 05:39 AM
  4. Image manipulation.
    By ambikark in forum Advanced Java
    Replies: 0
    Last Post: 10-15-2008, 01:37 PM
  5. why do I got this error about the constructor ?
    By aneuryzma in forum New To Java
    Replies: 4
    Last Post: 08-14-2008, 10:22 PM

Posting Permissions

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