0

demo

Code:

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;
}

I am trying to generate a thumbnail from an image in the above code.

When I call the above function, it launches a Java icon, which is shown in my attached screenshot. If I try to close this icon, my application gets closed.

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
  • Can you please provide the context in which you are calling the method? – AlterV Aug 18 '16 at 15:36
  • I guess i have already written that in my post above, i am trying to generate a thumbnail for a given image. I have a byte[] array of a image, and i need a byte[] for a thumbnail. – Vyomkesh Tiwari Aug 18 '16 at 19:20
  • I tried to debug the code, the java icon is getting launched at : `Thumbnails.of(inputStream).size(50, 50).keepAspectRatio(true) .outputFormat("jpg").toOutputStream(outputStream); ` – Vyomkesh Tiwari Aug 19 '16 at 06:59
  • Welcome to Stack Overflow! Can you please have a better title and more detailed information in the content with your effort to solve the problem? – Enamul Hassan Aug 21 '16 at 00:32

1 Answers1

1

The dock icon appears, because some of the imaging code you use, use awt under the hoods. This triggers the dock icon to appear on OS X. It's possible to suppress the icon, though.

The cross platform way of doing it, is running you application in "headless" mode, that is, with no user interaction using mouse, keyboard or screen feedback (ie. windows). You can specify headless mode at startup, using the system property java.awt.headless on the command line like this:

java -Djava.awt.headless=true 

Alternatively, in code like this:

System.setProperty("java.awt.headless", "true"); 

For OS X (and an Apple JRE) you can alternatively use the system property apple.awt.UIElement, it will suppress the dock icon only, but otherwise let your app use windows etc.:

java -Dapple.awt.UIElement=true

From the documentation:

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.

Harald K
  • 26,314
  • 7
  • 65
  • 111