Class Pixel
[code]package Pixel;
public class Pixel {
private int pixel;
public int getPixel() {
return pixel;
}
public void setPixel(int pixel) {
this.pixel = pixel;
}
}[/code]
Class Matrix Pixel
package MatImg;
import Pixel.Pixel;
public class MatrixPixel{
private static int ncol = 600;
private static int nlin = 800;
private Pixel[][] mPixel = new Pixel[nlin][ncol];
public void addPixelInMat(Pixel pixel, int i, int j) {
this.mPixel[i][j] = pixel;
}
/*public Pixel getPixelInMat(MatrixPixel mPixel, int i, int j) {
return getPixel(mPixel[i][j]);
}*/
public static int getPixelInMat(Pixel pixel, int i, int j){
return pixel.getPixel();
}
public static int getCol() {
return ncol;
}
public static int getLin() {
return nlin;
}
}
Class Create Matrix
package MatImg;
import java.io.FileInputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
import Pixel.Pixel;
public class CreateMatrix {
public CreateMatrix(String directory , MatrixPixel mPixel) {
Pixel pixel = new Pixel();
try{
FileInputStream image;
image = new FileInputStream(directory);
for (int i = 0; i < MatrixPixel.getLin(); i++){
for (int j = 0; j < MatrixPixel.getCol(); j++){
pixel.setPixel(image.read());
mPixel.addPixelInMat(pixel, i, j);
//System.out.println("Num.: " + pixel.setPixel(image.read()));
}
}
image.close();
JOptionPane.showMessageDialog(null, "Image Load" + directory);
}catch (IOException e){
JOptionPane.showMessageDialog(null, "File Not Found" + directory);
}
}
}
package MatImg;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
import Pixel.Pixel;
public class SaveImg {
public SaveImg(String directory, MatrixPixel save){
Pixel pixel = new Pixel();
try{
FileOutputStream image;
image = new FileOutputStream(directory);
for (int i = 0; i < MatrixPixel.getLin(); i++){
for (int j = 0; j < MatrixPixel.getCol(); j++){
image.write(MatrixPixel.getPixelInMat(pixel, i, j));
}
}
image.close();
JOptionPane.showMessageDialog(null, "Image Save in " + directory);
}catch (IOException e){
JOptionPane.showMessageDialog(null, "File Don't Save" + directory);
}
}
}
Estou estanciando a partir dessa classe
package ControlProgram;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class ButtonAction extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
JPanel Buttons , SP;
JButton ButtonB3, ButtonB4, ButtonB5, ButtonStat;
JScrollPane ScrollBar;
public static JTextArea TA;
MatImg.MatrixPixel IMG = new MatImg.MatrixPixel();
ButtonAction(){//Estancio os Elementos e Adiciono nos Painéis e Adiciono Ação Nos Botões
//Estanciando os Objetos
MatImg.MatrixPixel IMG = new MatImg.MatrixPixel();
Buttons = new JPanel();
SP = new JPanel();
ButtonB3 = new JButton("Load");
ButtonB4 = new JButton("HBanda4");
ButtonB5 = new JButton("HBanda5");
ButtonStat = new JButton("SaveIMG");
TA = new JTextArea(38,33);
ScrollBar = new JScrollPane(TA);
//Adicionando os Elementos no Painel
Buttons.add(ButtonB3);
Buttons.add(ButtonB4);
Buttons.add(ButtonB5);
Buttons.add(ButtonStat);
SP.add(ScrollBar);
//Adicionando Acão Nos Botões
ButtonB3.addActionListener((ActionListener) this);
ButtonB4.addActionListener((ActionListener) this);
ButtonB5.addActionListener((ActionListener) this);
ButtonStat.addActionListener((ActionListener) this);
new MatImg.CreateMatrix("C:\\banda3.raw", IMG);
new MatImg.SaveImg("C:\\Users\\BrunoMoreira\\Desktop\\teste_OUT.raw", IMG);
//C:\\Users\\BrunoMoreira\\Desktop\\banda3_out.raw
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == ButtonB3) {
new MatImg.CreateMatrix("C:\\banda3.raw", IMG);
}
if (e.getSource() == ButtonB4){
}
if (e.getSource() == ButtonB5){
}
if (e.getSource() == ButtonStat) {
new MatImg.SaveImg("C:\\Users\\BrunoMoreira\\Desktop\\OO_OUT.raw", IMG);
}
}
}
Pessoal fiz o objeto Pixel, e com ele fazer uma Matriz de objetos Pixel, e essa matriz irá conter os valores dos pixel de uma imagem Raw, ou seja carregar os dados da imagem para a Matriz que criamos, e tambem deverá salvar essa matriz em uma nova imagem, porém quando abro essa nova imagem ela fica toda preta porque não está recebendo os valores certo dos pixels, pois só é salvo os valores iniciais que é 0 (preto absoluto). Queria saber ond estou errando e minha estrutura?
Desde ja agradeço a atenção de todos
E a ajuda de todos também
att
Bruno Moreira
:!: