Mirror an image
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 =E9 o m=E9todo para implementar o espelhamento
// s=F3 devem utilizar os m=E9todos 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();
=09
// 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=E1rio da linha seguinte, para teste
newPixelColor = pixelRGB + 0xFF;
newPixelColor = pixelRGB & 0xFF;
newPixelColor = pixelRGB & 0xFF00;
newPixelColor = pixelRGB & 0xFF0000;
image.setRGB(x, y, newPixelColor);
}
}
}
/**
* M=E9todo de inicializa=E7=E3o da frame
*
* @throws IOException
*/
public static void init() throws IOException {
// criar uma JFrame
JFrame frame = new JFrame();
// colocar umas dimens=F5es simp=E1ticas
frame.setSize(1000, 900);
// centr=E1-la
frame.setLocationRelativeTo(null);
// Ler a imagem para uma BufferedImage
BufferedImage image = ImageIO.read(new File("image1.jpg"));
// Executar a transforma=E7=E3o =E0 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 =E0 frame
frame.add(label);
// colocar a frame vis=EDvel
frame.setVisible(true);
}
/**
* M=E9todo main
*
* @param args
*/
public static void main(String[] args) {
// enviar a ac=E7=E3o para execu=E7=E3o
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
// init() =E9 a ac=E7=E3o 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