JavaScript is required to use Bungie.net

자유 게시판

자유롭게 대화를 나누어보세요.
작성자: colbyrules8 10/25/2013 2:11:14 AM
5

Help with Java Programming

I just finished up with a simple project we had for Computer Science 1302 and I saw that there was extra credit for it and I was wondering if any of you could help me out with it. The program itself simply takes a BMP image and makes it black and white and creates the new output file within the same folder as the original image (Which has to be in your projects folder). The extra credit that I simply need help with is : [b]show the outputted file in a ScrollPane (hint: requires ImageIO class to show a BMP in an ImageIcon).[/b] Here is the code: [quote] import java.io.*; import javax.swing.*; public class Bitmapper { public static void main(String[] args) throws IOException { //ask user for a file (BMP) to open JFileChooser chooser = new JFileChooser(); int status = chooser.showOpenDialog(null); if (status != JFileChooser.APPROVE_OPTION) { JOptionPane.showMessageDialog(null, "No file chosen."); } else { File file = chooser.getSelectedFile(); String outfile = chooser.getSelectedFile().getParentFile().getAbsolutePath(); String inName = file.getName(); // input file name to string outfile += "\\" + inName.substring(0, inName.length() -4) + "_gray.bmp"; // generate output file name // Handling binary (not text) data, so use FileInputStream FileInputStream in = new FileInputStream(file); FileOutputStream out = new FileOutputStream(outfile); int B, G, R = 0; int counter = 0; while((B=in.read())!=-1) { if (++counter>54) // skip past Bitmap headers { G = in.read(); //read green and blue bytes R = in.read(); int gray = (B + G + R)/3; B = gray; G = gray; R = gray; out.write(R); out.write(G); //B = Math.min(B+100, 255); // Lighten image } out.write(B); } in.close(); out.close(); } } } [/quote]

게시물 작성 언어:

 

다른 사용자들을 존중해주세요. 게시물을 제출하기 전에 한 숨 돌리고 운영 정책을 검토하세요. 취소 수정 화력팀 생성하기 게시

  • Sorry for bumping but I just want to see if anyone can add onto what suppressor said. He helped out quite a bit but I am still a bit confused as the extra credit portions are coding we haven't learned yet. Basically our labs and projects cover what we learned and the extra credit is implementing something from the next section so we have to go out of our way to learn about it.

    게시물 작성 언어:

     

    다른 사용자들을 존중해주세요. 게시물을 제출하기 전에 한 숨 돌리고 운영 정책을 검토하세요. 취소 수정 화력팀 생성하기 게시

  • Xbox.com? [spoiler]I no likey these com putters, and the interwebs with wifer it confuses me.[/spoiler]

    게시물 작성 언어:

     

    다른 사용자들을 존중해주세요. 게시물을 제출하기 전에 한 숨 돌리고 운영 정책을 검토하세요. 취소 수정 화력팀 생성하기 게시

  • Nothing?

    게시물 작성 언어:

     

    다른 사용자들을 존중해주세요. 게시물을 제출하기 전에 한 숨 돌리고 운영 정책을 검토하세요. 취소 수정 화력팀 생성하기 게시

  • 작성자: Emacs 10/25/2013 2:14:21 AM
    If you need to grey scale the image, you need to average all of the colour channel values in each pixel, and set each of the channels equal to that average value. If it's strictly Black and White, then you need to set the colour channel values to 00 or FF based on the average being over or under some value. I'm not sure all of the libraries you're using (images and interface) are standard, so I can't help with that.

    게시물 작성 언어:

     

    다른 사용자들을 존중해주세요. 게시물을 제출하기 전에 한 숨 돌리고 운영 정책을 검토하세요. 취소 수정 화력팀 생성하기 게시

    5 답변
    • 0
      Yes.

      게시물 작성 언어:

       

      다른 사용자들을 존중해주세요. 게시물을 제출하기 전에 한 숨 돌리고 운영 정책을 검토하세요. 취소 수정 화력팀 생성하기 게시

      1 답변
      회원님은 해당 콘텐츠를 볼 수 없습니다.
      ;
      preload icon
      preload icon
      preload icon