Processamento de Imagens JPEG

3 respostas
L

Pessoal estou tentando compilar o codigo abaixo e nao estou conseguindo encontrar uma solução. Alguem poderia propor uma solução para o codigo?
Ja tentei de tudo e não consegui compilar, este codigo.

public static void main(String[] args) throws IOException
{

BufferedImage image = ImageIO.read(new File("100_9.JPG"));
	
	JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(image);
	
	int width = image.getWidth();
	
	int height = image.getHeight();
	
	int nbands = image.getSampleModel().getNumBands();
	
	Raster inputRaster = image.getData();
	
	int[] pixels = new int[nbands*width*height];
	
	inputRaster.getPixels(0,0,width,height,pixels);
	
	for(int h=0;h<height;h++)
		for(int w=0;w<width;w++)
			{
			int offset = h*width*nbands+w*nbands;
			System.out.print("at ("+w+","+h+"): ");
			for(int band=0;band<nbands;band++)
			System.out.print(pixels[offset+band]+" ");
			}
}

Os erros são os seguintes:
Cannot resolve symbol variable ImageIO
Cannot resolve symbol createJPEGDecoder (java.awt.image.BufferedImage)

Obrigado

3 Respostas

raphael_adrien

Tenta assim.

public static void main(String[] args)  {
        
        try{
            
            BufferedImage image = ImageIO.read(new File("C:\\tmp\\austria.jpg"));
            
            File file               = new File("C:\\tmp\\austria.jpg");
            FileInputStream input   = new FileInputStream( file );
            
            JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder( input );
            
            int width = image.getWidth();
            
            int height = image.getHeight();
            
            int nbands = image.getSampleModel().getNumBands();
            
            Raster inputRaster = image.getData();
            
            int[] pixels = new int[nbands*width*height];
            
            inputRaster.getPixels(0,0,width,height,pixels);
            
            for(int h=0;h<height;h++)
                for(int w=0;w<width;w++) {
                int offset = h*width*nbands+w*nbands;
                System.out.print("at ("+w+","+h+"): ");
                for(int band=0;band<nbands;band++)
                    System.out.print(pixels[offset+band]+" ");
                }
            
        } catch( IOException ex ){
            ex.printStackTrace();
        }
        
    }
Marky.Vasconcelos

Você tem o import de javax.imageio.ImageIO
Não lembro se é bem esse mas você o importou?

L
Opa não importei esse  nao, tava tao desesperado olha o tanto de coisa q eu importei:

package jai;

import java.awt.Transparency;

import java.io.IOException;

import java.awt.image.<em>;

import <a href="http://java.io">java.io</a>.</em>;

import java.net.MalformedURLException;

import java.net.URL;

import javax.media.jai.*;

import java.awt.image.SampleModel;

import com.sun.image.codec.jpeg.JPEGCodec;

import com.sun.image.codec.jpeg.JPEGImageDecoder;

import java.awt.Graphics2D;

import java.awt.Image;

import java.awt.RenderingHints;

import java.awt.image.BufferedImage;

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.net.MalformedURLException;

import javax.swing.ImageIcon;

import com.sun.image.codec.jpeg.ImageFormatException;

import com.sun.image.codec.jpeg.JPEGCodec;

import com.sun.image.codec.jpeg.JPEGEncodeParam;

import com.sun.image.codec.jpeg.JPEGImageEncoder;
Criado 14 de setembro de 2007
Ultima resposta 16 de set. de 2007
Respostas 3
Participantes 3