2009-12-09 3 views
2

Java 6 (1.6.0_17 JVM : 14.3-b01-101)의 OSX (10.5.8)에서 AWT 클래스를 사용하는 데 문제가 있습니다. 코드가 멈추는 java.awt.Dimension을로드하려고 시도하면 Eclipse 또는 명령 행에서 발생합니다. 누구나 같은 문제가 발생 했습니까? 클래스는 다음 코드 JAI에 의해 사용됩니다OSX의 JNI 문제

public static byte[] resizeAsJPG(byte[] imageContent, double scale, float outputQuality) throws IllegalArgumentException, 
    ImageOperationException { 
if (scale <= 0) { 
    throw new IllegalArgumentException("scale must be a positive number"); 
} 
if (outputQuality <= 0 || outputQuality > 1.0F) { 
    throw new IllegalArgumentException("outputQuality must be between 0 and 1"); 
} 
try { 
    // Fetch input image to seekable stream 
    RenderedOp originalImage = getRenderedOp(imageContent); 
    ((OpImage) originalImage.getRendering()).setTileCache(null); 

    // Set scale parameters 
    ParameterBlock saclingParams = new ParameterBlock(); 
    saclingParams.addSource(originalImage); // The source image 
    saclingParams.add(scale); // The xScale 
    saclingParams.add(scale); // The yScale 
    saclingParams.add(0.0); // The x translation 
    saclingParams.add(0.0); // The y translation 

    // RenderingHints renderingHints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 
    Map<RenderingHints.Key, Object> renderingHints = new HashMap<RenderingHints.Key, Object>(); 
    renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 
    renderingHints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); 
    renderingHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); 
    renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 

    // Scale using sub-sampling average which provides much better quality than bicubic interpolation 
    RenderedOp scaledImage = JAI.create("SubsampleAverage", saclingParams, new RenderingHints(renderingHints)); 

    // Encode scaled image as JPEG 
    JPEGEncodeParam encodeParam = new JPEGEncodeParam(); 
    encodeParam.setQuality(outputQuality); 

    // Since we scale height and width (don't take into account the quality) 
    int outputSizeEstimate = (int) (imageContent.length * scale * scale); 
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(outputSizeEstimate); 
    ImageEncoder encoder = ImageCodec.createImageEncoder("JPEG", outputStream, encodeParam); 
    encoder.encode(scaledImage); 
    return outputStream.toByteArray(); 
} catch (Exception e) { 
    throw new ImageOperationException(e.getMessage(), e); 
} 

}

답변

0
당신은 AWT 클래스를 수 있도록 명령 줄에서 "-Djava.awt.headless는 = true"로 플래그를 설정하려고 할 수도 있습니다

GUI를 초기화하지 않고도 실행할 수 있습니다.

+0

도움이되지 않았습니다. – talg