Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to watch BufferedImage objects while debugging in IntelliJ?

Is it possible to watch BufferedImage objects while debugging in IntelliJ?

I mean to view visual content of an image, not memory identity.

Is it also possible to view custom objects visually, i.e. write some custom visualizers?

like image 433
Dims Avatar asked Sep 22 '15 08:09

Dims


People also ask

How do I enable trace current stream chain in IntelliJ?

On the right-hand side of the debug window, click the button called Trace Current Stream Chain. This tells IntelliJ IDEA to evaluate our stream, and this is how you get your visual representation.

How do I create a view in IntelliJ?

To view a table, double-click the table. For more information about different viewing modes, see View data. The available data sources are shown as a tree of data sources, schemas, tables and columns. If no data sources are currently defined, use the New command Alt+Insert to create a data source.

How do I monitor threads in IntelliJ?

You can customize how threads are displayed on the Frames and Threads tabs. It might be helpful when you are working on a multithreaded application and often need to access information about your threads. Right-click anywhere in the Frames or Threads tab and select Customize Threads View.


1 Answers

IntelliJ IDEA 2016.1.1 is able to display BufferedImage object as image while debugging by default (probabily previous versions also support this feature).

  1. Set up a breakpoint where you can access the BufferedImage object
  2. By default, for BufferedImage class Idea will set Image viewer, so you can simply click on the View image text in the row of the BufferedImage object in the debugger window, on the very right hand side. This is also available in the Evaluate Expression window. Image viewer while debugging in IDEA
  3. In case another viewer is set for the BufferedImage class, you can change it back by right clicking on the BufferedImage object in the debugger window, and select View as / Image.

The image will be loaded in a popup window. (You can resize the the popup, but cannot move. I'm on OS X, the window handling of Idea is a bit weird here, maybe better on Win)


You can also create your own object visualizers. This can also be done in the View as context menu, in this case choose the Create... option. There you can enter your custom expression, which will be displayed in the row of the object in the debugger window. Please note that this is for displaying information of the object in text format only.

For example if you want to display the BufferedImage as [width]x[height] in the debugger window, create a new view, select Use following expression radio button, and enter the following expression:

getWidth() + "x" + getHeight()

enter image description here

After clicking Apply or OK, you will get: enter image description here

You can manage your viewers by right clicking in the Variables or Watches panel, and select Customize Data Views...

like image 103
abrahala Avatar answered Sep 28 '22 06:09

abrahala