Results 1 to 3 of 3
  1. #1
    Hafsa Hosani is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Default Neec a help in this program (printing RGB into text file)

    Hello all,
    My program is to take a jpeg image and print the RGB values of its pixel into a text file. There is no syntax errors in the code, but is does not print the RGB values in the text file. otherwise, it print in the text file the error message that is shown in the catch statement.
    Here is the code:

    import javax.imageio.*;
    import java.awt.image.*;
    import java.io.*;
    public class BitRGB2{
    public void BitRGB2(){}
    public void init(){
    PrintStream errp=null;
    try{
    errp=new PrintStream(new FileOutputStream("rgb.txt"));
    }catch(IOException ioe){};
    try{
    System.setOut(errp);
    }catch(SecurityException se){};
    try{
    BufferedImage src=ImageIO.read(new File("science.jpg"));
    int w=src.getWidth();
    int h=src.getHeight();
    errp.print("pix=[[");
    for(int k=0;k<h;k++){
    for(int j=0;j<w;j++){
    //System.out.println(k+","+j+","+src.getRGB(k,j));
    errp.print(src.getRGB(j,k)+0xFFFFFF+1);
    if(j<(w-1)){
    errp.print(",");
    }
    }
    if(k<(h-1)){
    errp.print("], ");
    errp.println(" ");
    errp.print("[");
    }else{
    errp.print("]];");
    }
    }
    errp.close();
    }catch(IOException e){
    errp.println("Error . . ");
    }
    }
    public static void main(String args[]) {
    BitRGB2 bt=new BitRGB2();
    bt.init();
    }

    }

    You can put whatever image istead of mine (science.jpg). By the way, I put the image in the same package of the project.
    Can some body help me, please?

  2. #2
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default

    What's this bit in aid of?

    Java Code:
    errp.print(src.getRGB(j,k)<b>+0xFFFFFF+1</b>);
    And what format do you want the RGB values in?

  3. #3
    Hafsa Hosani is offline Member
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Java Text Printing
    By vivekn in forum Introductions
    Replies: 0
    Last Post: 03-13-2009, 09:05 AM
  2. Job name when printing file
    By pjmorce in forum Advanced Java
    Replies: 3
    Last Post: 12-23-2008, 02:55 AM
  3. printing simple text as text on printer
    By Nicholas Jordan in forum Advanced Java
    Replies: 0
    Last Post: 12-01-2008, 02:42 AM
  4. find and replace text from a text file
    By gezzel in forum New To Java
    Replies: 2
    Last Post: 09-19-2008, 05:04 PM
  5. A Fibonacci printing program
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-28-2008, 08:26 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
  •