Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

how to cut an image in java using jfilechooser to select the image and jfile chooser to save ?

 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the code im using to cut but how to use jfilechooser in it ?
ImagePanel.java




 
Niti Kapoor
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
basically i want load cut and save image in java
 
Rancher
Posts: 3078
24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the section from the Swing tutorial on How to Use File Choosers for working examples to get the file name.

Then you can use the read() or write() methods from the ImageIO class to read/write the file as required.
 
Bartender
Posts: 3588
151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some shortcomings in your program, apart from the use of JFileChoosers.
The biggest is that Robot works with screencoordinates, while the mouseEvent gives the panel coordinates. So, to make it work, you must translate the event coordinates to screencoordinates.
And to a lesser degree: with todays mega images, chances are that the image does not fit on the screen. let alone in the panel. There is no facility to drag the image around in the panel.

But maybe your code is just for relatively small images?
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!