Processamento de Imagens JPEG

2 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

2 Respostas

S

Tem certeza se a classe ImageIO e JPEGDecoder existem e estão no lugar certo?

M

opa,

tente assim:
public static void main(String[] args) {
		try {
			File file = new File(Teste.class.getResource("C:\\100_9.JPG").toString());
			if (file.exists()) {
				System.out.println("uau!");
			}
			BufferedImage image = ImageIO.read(file);
			//InputStream stream = new FileInputStream(file);
			//JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(stream);

			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 e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

:okok:

Criado 14 de setembro de 2007
Ultima resposta 18 de set. de 2007
Respostas 2
Participantes 3