Last active
May 30, 2017 23:24
-
-
Save sombriks/1de436d7743fc58ecfd4068bc6b0ddab to your computer and use it in GitHub Desktop.
muda a colunagem dum gpm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.io.PrintStream; | |
import java.nio.file.Paths; | |
import java.util.Scanner; | |
public class ArquivoPGM { | |
private int altura; | |
private int largura; | |
private int max; | |
private int[][] imagem;// = new int [altura][largura]; | |
public void carregaPGM(String caminho) throws Exception { | |
Scanner s = new Scanner(Paths.get(caminho)); | |
s.nextLine();// P2 | |
largura = s.nextInt(); | |
altura = s.nextInt(); | |
imagem = new int[this.largura][this.largura]; | |
max = s.nextInt(); // 255 | |
for (int i = 0; i < largura; i++) { | |
for (int j = 0; j < altura; j++) { | |
imagem[i][j] = s.nextInt(); | |
} | |
} | |
} | |
public void escrevePGM(String caminho) throws IOException { | |
PrintStream ps = new PrintStream(caminho); | |
ps.println("P2 "); | |
ps.printf("%d %d\n%d\n", 70, ((altura*altura)/70)+70, max); | |
int count = 0; | |
for (int i = 0; i < largura; i++) { | |
for (int j = 0; j < altura; j++) { | |
count++; | |
ps.printf("%d ", imagem[i][j]); | |
if (count == 70) { | |
ps.println(); | |
count = 0; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment