How do I crop an image in Java?

前端 未结 7 1346
逝去的感伤
逝去的感伤 2020-11-29 00:22

I want to crop an image manually using the mouse.
Suppose the image has some text, and I want to select some text from an image, then for that purpose I want to crop th

7条回答
  •  臣服心动
    2020-11-29 00:45

    You need to read about Java Image API and mouse-related API, maybe somewhere under the java.awt.event package.

    For a start, you need to be able to load and display the image to the screen, maybe you'll use a JPanel.

    Then from there, you will try implement a mouse motion listener interface and other related interfaces. Maybe you'll get tied on the mouseDragged method...

    For a mousedragged action, you will get the coordinate of the rectangle form by the drag...

    Then from these coordinates, you will get the subimage from the image you have and you sort of redraw it anew....

    And then display the cropped image... I don't know if this will work, just a product of my imagination... just a thought!

提交回复
热议问题