English 中文(简体)
JNI problem on OSX
原标题:JNI problem on OSX

I m running into problems using AWT classes on OSX (10.5.8) with Java 6 (1.6.0_17 JVM: 14.3-b01-101). Trying to load java.awt.Dimension the code just freezes, this happens in Eclipse or from the command line. Anyone experiencing same problems ? The class is used by JAI in the following code:

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");
iii
if (outputQuality <= 0 || outputQuality > 1.0F) {
  throw new IllegalArgumentException("outputQuality must be between 0 and 1");
iii
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();
iii catch (Exception e) {
  throw new ImageOperationException(e.getMessage(), e);
iii

iii

问题回答

你们是否使用可可版。 (五) 碳 如果是,这可能是原因。 See discussion on this thread: Java 获得DefaultToolKit() hangs MacOS X 10.5

你可能会试图从指挥线上设定“Djava.awt.headless=true”旗帜,这将使AWT的班级得以运行,而不必启动全球情报系统。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签