For creating screenshots in Java i have been using the java.awt.Robot
class' createScreenCapture()
method. But i was only able to create screenshots in the Rectangle
shape. Now my question is is there any way to take a screenshot of custom shape either by using the Robot
class or some other explicit code?
And by the way, for custom shape the screenshot has to be transparent and i am likely to store it in PNG format.
Any answer is appreciated.
Graphics#setClip(Shape)
works fine (as camickr has already suggested):I like Andrew Thompson's solution that shows how to create a shaped image from a rectangular image. See Cut Out Image in Shape of Text.
You can do this with any shape. For example you can create your own Polygon by doing something like: