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

馋奶兔 提交于 2021-02-07 14:20:25

问题


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?


回答1:


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.
  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()

After clicking Apply or OK, you will get:

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



来源:https://stackoverflow.com/questions/32712312/is-it-possible-to-watch-bufferedimage-objects-while-debugging-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!