Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

working with images  RSS feed

 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get the width and height attributes of an image, the only way I know to do this is using Image, with Buffered Image and all this, but this works REALLY slow, if I try to get at a time the attributes of 100 images it needs up to 60 seconds, and I'd like to do this for thousands of files, so this is not an option, anyone knows what I can do?? I really don't need to create the image, I just wan't those two numbers, there must be another way to get them. Any suggestion is welcome, thanks.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggested the following code in a similar thread:
But you said it was too slow. I tested it on my machine (which is modest) and I was able to get the size of 1000 files in 700 milliseconds!
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeff Albrechtsen,

I must apologize because as you say in another post about the same, you told me about ImageReader, but you weren't so speceific as in this, and I thought that you referred to BufferedImage, I'm so sorry, because as I've seen it's not the same. The thing is that this was the part of the job that a friend of mine had to do, but he wasn't able to create an image reader from a file's path (now I can imagine how much he tried). So as I say I hadn't done any research on the subject, but as it was too slow I wanted to improve his work, and now you've opened my eyes. So I'm sorry for double posting, but you can't imagine how useful this reply is to me. Now I've tested this code you've posted and it works great, so really, I mean it, thanks a lot.

PD: Now that we're here, can you explain me how I should do if I wanted to read different file types?? I suppose that this line:

Only allows me to read from jpg, JPG, jpeg and so, but I also need to read from gif and png, do you think something like this could work???


Well, thanks a lot, with five lines of code you've made my program much more efficient.

[ December 21, 2005: Message edited by: Emili Calonge ]
[ December 21, 2005: Message edited by: Emili Calonge ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying each image reader is not a good idea -- it's a misuse of exceptions. I can think of two approaches:
1. Get the suffix from the file:This assumes the suffixes are there and are accurate.

2. Use ImageIO.getImageReaders
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are trying to locate all files with a certain set of extensions, use the java.io.File method listFiles( FileNameFilter )
You just have to implement the FileNameFilter interface in a simple class that only accepts file names with one of the extensions you want.
Bill
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep I have a filename filter already, the file I have I know gor sure that has the extension I want, what I want now is to get the height and width for all the files I accept, I'll read your replies later and see if they work as now I don't have time, thanks anyway.
 
Emili Calonge
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, that's exactly what I needed, now it works perfectly and fast, as I have the files with correct exetnsions only as I first use a filenamefilter, I use now the suffix function and it works, so many thanks really, this means a big performance chance in my application (the only thing I don't like is that I had the presentation of the project last week, so the teachers won't see these changes). So this is all for now, thanks a lot. Bye!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!