Java 应用程序在尝试从图像字节数组生成缩略图时启动
Java application getting launched when trying to generate a thumbnail from a image byte array
代码:
public byte[] getThumbnail(byte[] imageBytes) throws Exception {
ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Thumbnails.of(inputStream).size(50, 50).keepAspectRatio(true)
.outputFormat("jpg").toOutputStream(outputStream);
byte[] picture = outputStream.toByteArray();
return picture;
}
我正在尝试从上面的代码中的图像生成缩略图。
当我调用上述函数时,它会启动一个 Java 图标,如我所附的屏幕截图所示。如果我尝试关闭此图标,我的应用程序将关闭。
停靠栏图标出现,因为您使用的某些图像代码在后台使用 awt
。这会触发停靠栏图标出现在 OS X 上。不过,可以隐藏该图标。
跨平台的做法是 运行 您的应用程序处于 "headless" 模式,即没有使用鼠标、键盘或屏幕反馈的用户交互(即 windows).您可以在启动时指定无头模式,在命令行上使用系统 属性 java.awt.headless
,如下所示:
java -Djava.awt.headless=true
或者,在这样的代码中:
System.setProperty("java.awt.headless", "true");
对于 OS X(和 Apple JRE),您可以选择使用系统 属性 apple.awt.UIElement
,它只会抑制 dock 图标,否则会让您的应用使用 windows等:
java -Dapple.awt.UIElement=true
Suppresses the normal application Dock icon and menu bar from appearing. Only appropriate for background applications which show a tray icon or other alternate user interface for accessing the apps windows. Unlike java.awt.headless=true
, this does not suppress windows and dialogs from actually appearing on screen.
The default value is false
.
代码:
public byte[] getThumbnail(byte[] imageBytes) throws Exception {
ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Thumbnails.of(inputStream).size(50, 50).keepAspectRatio(true)
.outputFormat("jpg").toOutputStream(outputStream);
byte[] picture = outputStream.toByteArray();
return picture;
}
我正在尝试从上面的代码中的图像生成缩略图。
当我调用上述函数时,它会启动一个 Java 图标,如我所附的屏幕截图所示。如果我尝试关闭此图标,我的应用程序将关闭。
停靠栏图标出现,因为您使用的某些图像代码在后台使用 awt
。这会触发停靠栏图标出现在 OS X 上。不过,可以隐藏该图标。
跨平台的做法是 运行 您的应用程序处于 "headless" 模式,即没有使用鼠标、键盘或屏幕反馈的用户交互(即 windows).您可以在启动时指定无头模式,在命令行上使用系统 属性 java.awt.headless
,如下所示:
java -Djava.awt.headless=true
或者,在这样的代码中:
System.setProperty("java.awt.headless", "true");
对于 OS X(和 Apple JRE),您可以选择使用系统 属性 apple.awt.UIElement
,它只会抑制 dock 图标,否则会让您的应用使用 windows等:
java -Dapple.awt.UIElement=true
Suppresses the normal application Dock icon and menu bar from appearing. Only appropriate for background applications which show a tray icon or other alternate user interface for accessing the apps windows. Unlike
java.awt.headless=true
, this does not suppress windows and dialogs from actually appearing on screen. The default value isfalse
.