Java에서 병렬 이미지 처리 스크립트를 만들려고했는데, 이미지를 어떤 크기의 타일로 나누어 처리하고 최종 이미지를 재구성하는 것이 좋습니다.전체 이미지를 메모리에 할당하지 않고 작은 이미지를 하나로 합치십시오.
은 지금 내가 함수 만들었습니다 BufferedImage로서 이미지의 영역을 반환
이public static BufferedImage readImg (String path, int startx, int starty, int w, int h)
, 다음 내가 그것을 처리 할 것을 나는 마지막의 올바른 위치에 그 지역을 배치 할 영상.
그래서 내가 메모리에 전체 이미지를로드하지 않고 올바른 위치에 바로 쓸 replacePixels에게 방법을 사용하는 기능 writeImg를 만들기 위해 노력했습니다는 : canReplacePixels 것을 항상 false로 설정
public static void writeImg (String path, int startx, int starty, BufferedImage image){
File output = new File(path);
ImageOutputStream ios = null;
try {
ios = ImageIO.createImageOutputStream(output);
} catch (IOException e){
e.printStackTrace();
}
Iterator iter = ImageIO.getImageWritersByFormatName("JPEG");
ImageWriter writer = (ImageWriter)iter.next();
writer.setOutput(ios);
try{
if(writer.canReplacePixels(0)){
System.out.println("True");
}else{
System.out.println("False");
}
}catch (IOException e) {
e.printStackTrace();
}
ImageWriteParam param = writer.getDefaultWriteParam();
Point destinationOffset = new Point(startx,starty);
param.setDestinationOffset(destinationOffset);
try {
writer.replacePixels(image, param);
} catch (IOException e) {
e.printStackTrace();
}
}
문제가 , 그리고 나는 그것을하기 위해 무엇을 사용해야하는지 모른다.
이미지가 너무 커질 수 있으므로 전체 이미지를 메모리에로드 할 수 없으므로 OutOfMemory 예외가 발생합니다.
와우 빠른 대답은, 물론 그 괜찮을 것, 또 다른 것은, 어떤 생각이 왜 replacePixels은 JPEG 이미지와 함께 작동하지 않습니다? 다른 언어 또는 다른 방법으로이를 수행하는 다른 방법은 없습니까? 줄이 여전히 크고 vjm의 메모리에 맞지 않으면 문제가 계속됩니다. – Alex88
또한 순서대로 줄을 제공해야합니다. 병렬 스레드가 순서대로 완료되지 않을 수도 있습니다. – Alex88
내 생각에 JPEG이 손실 압축 때문에 픽셀 대체가 작동하지 않습니다. PNG로이 작업을 시도 했습니까? 또는 다른 이미지 형식? – troutinator