Memory Drive

반응형

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();

}


}

}


결과...


반응형

'Computer_IT > JAVA' 카테고리의 다른 글

[MAVEN] unmappable character for encoding EUC_KR  (0) 2018.08.23
[spring] logback 로그 2번 찍힘  (0) 2018.08.09
JDK 7 release - Bug Fixes history  (0) 2014.10.20
eclipse @author 변경하기  (0) 2013.07.02
jackson parser sample  (0) 2013.04.02