1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public class ImageConverter {
public static ImageRGB convert(BufferedImage im) {
ImageRGB imageOut = new ImageRGB(im.getWidth(), im.getHeight());
for (int j = 0; j < im.getHeight(); j++)
for (int i = 0; i < im.getWidth(); i++) {
int rgb = im.getRGB(i, j);
Color couleur = new Color(rgb);
int r = couleur.getRed();
int g = couleur.getGreen();
int b = couleur.getBlue();
imageOut.setRedPixel(i, j, r);
imageOut.setGreenPixel(i, j, g);
imageOut.setBluePixel(i, j, b);
}
return imageOut;
}
public static BufferedImage convert(ImageRGB imageRGB) {
BufferedImage image = new BufferedImage(imageRGB.getWidth(), imageRGB
.getHeight(), BufferedImage.TYPE_INT_RGB);
for (int j = 0; j < imageRGB.getHeight(); j++)
for (int i = 0; i < imageRGB.getWidth(); i++) {
int fR = ColorConverter
.convertToInt(imageRGB.getRedPixel(i, j));
int fG = ColorConverter.convertToInt(imageRGB.getGreenPixel(i,
j));
int fB = ColorConverter.convertToInt(imageRGB
.getBluePixel(i, j));
Color color = new Color(fR, fG, fB);
image.setRGB(i, j, color.getRGB());
}
return image;
}
} |
Partager