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 8 of 8

Thread: Reading the text file contain binary and convert the binary into color or pixels

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

    Talking Reading the text file contain binary and convert the binary into color or pixels

    can anyone help me in my project. i need to convert the textfile contain binary into a color or pixels. I have the code but i cannot convert into a color or pixel. hopefully you can help me..
    this is the code:

    import java.awt.*; 
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    public class TEST1 extends Canvas {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws Exception {
            // TODO code application logic here} 
     
     
       try{
                    FileInputStream fstream = new FileInputStream("b.txt");
                    try (DataInputStream in = new DataInputStream(fstream)) {
                        BufferedReader br = new BufferedReader(new InputStreamReader(in));
     
     
                    int[][] datafile;
                    datafile=new int [40][40];
                    String strLine;
                    String[] getvalue =new String [50];
                    int cols;
                    int rows;
                    cols=0;
                    rows=0;
     
                                       while ((strLine = br.readLine()) != null)   {
     
                                          //opensplite-------------------------
                                            String smartPhones = strLine;
     
                                            String[] smartPhonesSplits = smartPhones.split("\\,");
     
                                            for(String smartPhone: smartPhonesSplits){
                                            datafile[rows][cols]= Integer.parseInt(smartPhone);
                                            rows=rows+1;
                                            }
                                           //closesplite-------------------------
                                           rows=0;
                                          cols=cols+1;
                                       }
                    //     cols=0;
     
                                        for( cols=0;cols<=7;cols++){
                                            for( rows=0;rows<=7;rows++){
                                                if(datafile[rows][cols]==1){
                                                   System.out.print(color.class.getClasses());
     
                                                }
                                                else{
                                                   System.out.print(" ");
                                                }
                                            }
                                            System.out.println();
     
                                            }
                    }
                    }catch (IOException | NumberFormatException e){
                      System.err.println("Error: " + e.getMessage());
                    }
        }
     
        private static class color {
     
            public void color() {
     
    } public void color(Graphics g){ 
     
    g.setColor(Color.blue); 
     
            }
     
     
        }
     
    }
    Last edited by helloworld922; January 21st, 2013 at 03:35 AM. Reason: please use [code] tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,337
    Thanks
    49
    Thanked 2,194 Times in 2,167 Posts

    Default Re: Reading the text file contain binary and convert the binary into color or pixels

    i need to convert the textfile contain binary
    What do you mean by "contain binary"? Do you mean that the file contains only the characters '0' and '1'?
    A sample line from the file would be a String like this: "0010101100".

    The posted code does not compile without errors.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading the text file contain binary and convert the binary into color or pixels

    Yes the 1011100 binary. Then each number represent a color
    Example 1 is black and 0 is white. When you console you can see an images in monochrome image

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,337
    Thanks
    49
    Thanked 2,194 Times in 2,167 Posts

    Default Re: Reading the text file contain binary and convert the binary into color or pixels

    Yes the 1011100 binary.
    I assume you mean: Yes the text is "1011100". The file contains the characters: '0' and '1'.

    Have you fixed the compiler errors yet? The posted code does not compile without errors.
    If you need help with the compiler errors, copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading the text file contain binary and convert the binary into color or pixels

    the code that i post don't have a error. i want the codes that generate the text file contain binary and print that in a color in a console. pls help me.. Thank you!

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,337
    Thanks
    49
    Thanked 2,194 Times in 2,167 Posts

    Default Re: Reading the text file contain binary and convert the binary into color or pixels

    The code needs the 1.7 javac.

    What problems are you having?

    Can you explain how the "0"s and "1" from the text file are to be used to create an image?
    What is the size (width and height) of the image?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Reading the text file contain binary and convert the binary into color or pixels

    Yes the 0 and 1 will create an image. Example the 0 will black and the 1 will be white. When you console it you can see a part of an image in monochrome. Not necessary the size of the image. Only i need is the 0 and 1 will be convert it.

    I have a problem also that a 16 color will display in a console. The same function. Example will be the number 0 to 15 in 16 colors. 0 is black, 1 is white, 2 is red is so forth... Thank you!

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,337
    Thanks
    49
    Thanked 2,194 Times in 2,167 Posts

    Default Re: Reading the text file contain binary and convert the binary into color or pixels

    So if the next char in the file is a '0' the color of the next pixel should be black
    and if '1' the color should be white.

    How are you creating an image and setting its pixels using the characters from the file?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Binary File. Extract float data from binary file and put into array
    By cardinal152 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: June 13th, 2012, 07:31 PM
  2. Binary datafile and object creation according to binary tag ?
    By loicus in forum Object Oriented Programming
    Replies: 4
    Last Post: October 14th, 2011, 01:00 PM
  3. Reading an int from bytes(binary file) - HELP
    By yogiyogi in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 14th, 2010, 01:03 PM
  4. Reading a writing binary file
    By stu1811 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: July 30th, 2010, 12:58 PM
  5. How to save statistics of a game in a binary file instead of txt file?
    By FretDancer69 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: June 19th, 2009, 05:05 AM