Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27930

Mirror an image

Newsgroups comp.lang.java.programmer
Date 2014-04-01 07:44 -0700
Message-ID <2299213c-18fc-4e55-ab39-22dce863b255@googlegroups.com> (permalink)
Subject Mirror an image
From pgmbento93@gmail.com

Show all headers | View raw


hi, i was confronted with this problem. i was given a code where i have to mirror an image at the middle. so the image needs to be divided and then i have to mirror the image. this is the code:

package tps.tp1.pack3Arrays;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

/**
 * Esta classe visa aplicar uma transformada ao pixel a uma imagem. Coloque a
 * imagem na raiz do seu projecto java.
 * 
 * @author ateofilo
 * 
 */
public class C07BitmapTransform {

	// TODO este é o método para implementar o espelhamento
	// só devem utilizar os métodos de image.getRGB e image.SetRGB
	public static void transformImage(BufferedImage image) {
		// obter a altura e largura da imagem em pixels
		int height = image.getHeight();
		int width = image.getWidth();
		
		// percorrer todos os pixels da imagem
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				int pixelRGB = image.getRGB(x, y);
				int newPixelColor = pixelRGB;
				// TODO retirar o comentário da linha seguinte, para teste
				newPixelColor = pixelRGB + 0xFF;
				newPixelColor = pixelRGB & 0xFF;
				newPixelColor = pixelRGB & 0xFF00;
				newPixelColor = pixelRGB & 0xFF0000;


				image.setRGB(x, y, newPixelColor);
			}
		}
	}

	/**
	 * Método de inicialização da frame
	 * 
	 * @throws IOException
	 */
	public static void init() throws IOException {
		// criar uma JFrame
		JFrame frame = new JFrame();
		// colocar umas dimensões simpáticas
		frame.setSize(1000, 900);
		// centrá-la
		frame.setLocationRelativeTo(null);

		// Ler a imagem para uma BufferedImage
		BufferedImage image = ImageIO.read(new File("image1.jpg")); 

		// Executar a transformação à imagem
		transformImage(image);

		// mostrar a imagem no centro de um JLabel
		ImageIcon img = new ImageIcon(image);
		JLabel label = new JLabel(img, JLabel.CENTER);
		// Adicionar a label à frame
		frame.add(label);

		// colocar a frame visível
		frame.setVisible(true);
	}

	/**
	 * Método main
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// enviar a acção para execução
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				try {
					// init() é a acção a executar
					init();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		});
	}

}

dont pay attention to the the comments.. what can i do? im new in java and i dont know what to do

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Mirror an image pgmbento93@gmail.com - 2014-04-01 07:44 -0700
  Re: Mirror an image Jeff Higgins <jeff@invalid.invalid> - 2014-04-01 11:09 -0400
    Re: Mirror an image Jeff Higgins <jeff@invalid.invalid> - 2014-04-01 11:15 -0400
  Re: Mirror an image Roedy Green <see_website@mindprod.com.invalid> - 2014-04-01 11:56 -0700
    Re: Mirror an image Wanja Gayk <brixomatic@yahoo.com> - 2014-04-06 20:18 +0200
      Re: Mirror an image Jeff Higgins <jeff@invalid.invalid> - 2014-04-06 18:01 -0400
        Re: Mirror an image Wanja Gayk <brixomatic@yahoo.com> - 2014-04-13 15:57 +0200
          Re: Mirror an image Jeff Higgins <jeff@invalid.invalid> - 2014-04-13 10:21 -0400

csiph-web