Computer_IT/JAVA 2015.06.17 23:55

Java에서 Bitmap을 Pixel 단위로 처리 할때 샘플...


 

Source...

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.IOException;


import javax.imageio.ImageIO;


public class BufferedImagePixels {

public static void main(String[] args) {


BufferedImage bufferedImage = new BufferedImage(300, 300,

BufferedImage.TYPE_INT_RGB);


int rgb = bufferedImage.getRGB(1, 1);


int w = bufferedImage.getWidth(null);

int h = bufferedImage.getHeight(null);

int[] rgbs = new int[w * h];

bufferedImage.getRGB(0, 0, w, h, rgbs, 0, w);


rgb = 0xFF00FF00; // green


for (int i = 1; i < w; i++) {

bufferedImage.setRGB(i, i, rgb);

}


File outputfile = new File("c:\\image.png");

try {

// png, 

ImageIO.write(bufferedImage, "png", outputfile);

} catch (IOException e) {

e.printStackTrace();

}


}

}


결과...


posted by 고급코드 고급코드