그래서 오늘 새 프로젝트를 시작했습니다. 나는 자바 간단한 높이 맵 생성기를 만들고 싶어, 그래서 나는 다음과 같은 시도 :Java : 내 높이 맵 생성기는 바이너리 만 기록합니다.
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Heightmap {
public static int width = 200;
public static int height = 200;
public static void main(String[] args) {
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
bufferedImage.setRGB(x, y, (byte)(Math.random() * 256 + 128)); // + 128 because byte goes from -128 to 127
}
}
File outputFile = new File("heightmap.png");
try {
ImageIO.write(bufferedImage, "png", outputFile);
}catch (IOException ioex){
ioex.printStackTrace();
}
}
}
코드는 매우 간단합니다, 나는 다음 단계로 소음 펄린 시도 할 계획이다. 중 하나를 완전히 흰색, 또는 완전히 검은 색 heightmap.png에 Generated Heightmap
픽셀 :하지만 먼저 나는이 문제를 해결해야합니다. 이미지에는 회색이 없으며 하이트 맵에는 물론 필요합니다. 아무도 내가 뭘 잘못했는지 알아?
은 BufferedImage.TYPE_BYTE_GRAY
부분입니까? 그렇다면 대신 무엇을 사용해야합니까?