Problema ao gravar a imagem

0 respostas
S
File input = new File(file);
        int cont = 0;


        BufferedImage image = ImageIO.read(input);

        BufferedImage decompressedimg = new BufferedImage(image.getWidth() / 2, image.getHeight(), BufferedImage.TYPE_INT_RGB);


        //filling matrix compressed image

        //decompressing image
        int aux = (image.getWidth() / 2) - 1;
        for (int i = 0; i < image.getHeight(); i++) {
            for (int j = 0; j < image.getWidth() - 1; j++) {
                if (j % 2 == 0 && cont < aux) {
                    int num_rep = image.getRGB(j, i) * -1;
                    int pixel = image.getRGB(j + 1, i);
                    for (int x = 0; x < num_rep && cont < aux; x++) {
                        decompressedimg.setRGB(cont, i, pixel);
                        //System.out.println(cont);
                        cont++;

                    }


                }
            }
        }

        try {
            File outputfile2 = new File("test.bmp");
            ImageIO.write(decompressedimg, "bmp", outputfile2);
        } catch (IOException ex) {
            System.out.print(cont);
            Logger.getLogger(RLE.class.getName()).log(Level.SEVERE, null, ex);
        }
preciso de uma ajudinha pessoal isto supostamente deveria descomprimir uma imagem so que cria uma imagem toda preta nao sei porque nem consigo entender. o metodo de compressao é o seguinte
public void compress2(BufferedImage img) {
        int[][] matrix = new int[img.getWidth()][img.getHeight()];

        int cpheight = img.getHeight();
        int cpwight = img.getWidth() * 2;
        BufferedImage compressedimg = new BufferedImage(cpwight, cpheight, BufferedImage.TYPE_INT_RGB);

        for (int i = 0; i < img.getHeight(); i++) {
            for (int j = 0; j < img.getWidth(); j++) {
                matrix[j][i] = img.getRGB(j, i);
                //System.out.print(" "+matrix[j][i]);
            }
        }

        try {

            for (int j = 0; j < img.getHeight(); j++) {
                int count = -1;
                int current = 0;
                int next = 0;
                int index = 0;

                for (int i = 0; i < img.getWidth() - 1; i++) {
                    // System.out.print(" "+matrix[0][j]);
                    current = matrix[i][j];
                    next = matrix[i + 1][j];
                    if (current != next) {

                        compressedimg.setRGB(index, j, count);
                        compressedimg.setRGB(index + 1, j, current);
                        index = index + 2;
                        count = -1;
                    } else {
                        count--;
                    }
                }


//            
            }
            System.out.println();

            File outputfile = new File("saved2.bmp");

            ImageIO.write(compressedimg, "bmp", outputfile);
        } catch (IOException ex) {
            Logger.getLogger(RLE.class.getName()).log(Level.SEVERE, null, ex);
        }

o metodo é o RLE agora porfavor me digam porque nao guarda uma imagem com pixeis e guarda tudo preto

Criado 23 de janeiro de 2010
Respostas 0
Participantes 1