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: Writing Image to Text File

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Writing Image to Text File

    I am trying to do an OCR where it take an image and return the content of the image in text file. The current code is working fine but it is not writing in text. Can anyone suggest/show me the way to make the output to be written in text file (.txt)?

    Here is the code:

    package assignment10;
     
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.io.*;
    import java.util.Arrays;
     
    import javax.imageio.ImageIO;
     
     
    public class A10Driver {
     
      /**
       * @param args
       * @throws IOException 
       */
      public static void main(String[] args) throws IOException {
        String name = "Translation_Standard_Galactic_Alphabet.png";
        double factor  = 0.3;
     
        System.out.println(Arrays.toString(args));
     
    //    if(args.length < 1){
    //      System.out.println("Usage: java -jar Filename.jpg");
    //      System.out.println("Exiting ...");
    //      System.exit(0);
    //    }
    //
    //
    //    String name = args[0];
    //    double factor = Double.parseDouble(args[1]);
     
        String[] arr = name.split("\\.");
        String format = arr[1];
     
     
        BufferedImage image  = ImageIO.read(new File(name));
        BoundaryFilterOp bOp = new BoundaryFilterOp(factor);
        BufferedImage bImg   = bOp.filter(image, null);
        //    IPUtil.displayMatrix(IPUtil.readImageAsMatrix(image));
        File file = new File("boundaryFilter-"+name);
        ImageIO.write(bImg, format, file);
     
      }
     
    }

    Please look into it as your help will mean a lot for my project. Thanks in advance!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Writing Image to Text File

    output to be written in text file
    What text do you want written to the text file? The PrintWriter class could be used to do the writing.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Writing to output text file
    By gatorsgirl in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: May 13th, 2012, 08:17 PM
  2. Beginner I/O Help: Writing To a Text File At the End of Existing Lines of Text
    By BloomingNutria in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 28th, 2012, 03:03 PM
  3. Help writing to a text file on a website!
    By straw in forum File I/O & Other I/O Streams
    Replies: 10
    Last Post: September 11th, 2011, 11:02 AM
  4. Issues with writing to text file
    By surfbumb in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 12th, 2011, 09:43 AM
  5. Writing to a specific line in a text file
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 7th, 2011, 09:11 PM