问题
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).
- Set up a breakpoint where you can access the
BufferedImage
object - By default, for
BufferedImage
class Idea will set Image viewer, so you can simply click on the View image text in the row of theBufferedImage
object in the debugger window, on the very right hand side. This is also available in the Evaluate Expression window. - In case another viewer is set for the
BufferedImage
class, you can change it back by right clicking on theBufferedImage
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