This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

How to import Image file

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have to import image file (.jpg). My code is working for text file. I am not getting why it's not working for image. Please have a look following code to import text file.



But my code for image file is not working which are as follow:


After importing I have to divides in 5 part and regenerate choosing any three part. Any one can help me?


Thanking you
 
Marshal
Posts: 24826
60
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You go to great trouble to display a JFileChooser and allow the user to select a file. But then you don't pay any attention to what file the user selected, and instead you create an image from no file at all:

You'll need to provide the path which the user selected here.

Secondly, you go to far too much trouble with that JFileChooser code. Here's your code which is complicated and doesn't always work properly:

That is only going to work on Windows systems (other systems use / to separate entries in the file path) and, more importantly, it will only work if the user chose a file from the file chooser's default directory. (At least I think that's right -- the documentation doesn't say what the "current directory" of a JFileChooser is.) Here's some code which is both simpler and more reliable:

You don't need to change the path to all lower-case either. That's another thing which is Windows-only and will fail on other operating systems, but you don't even need to do it on Windows systems.
 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Still I am not able to import any image on pane using FileChooser. Please help me.


Thanking You
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yatin Shah wrote:Still I am not able to import any image on pane using FileChooser.


What does that mean? How did you change your code?
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
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!