Results 1 to 5 of 5
- 08-25-2012, 12:55 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 12
- Rep Power
- 0
How to manage files in file chooser
Hello everybody.
I am building an Image Viewer like the one the Windows has.
One of the choices I offer the user is to enter the directory he wants through a file chooser and display the images in it(one at a time via arrow buttons)and then choose the one he likes.The problem is that I keep every picture of the directory in arrays(one array for the icons,another for filepaths etc).Is there any smarter way to do that?This turns out to be a problem in another thing I want to achieve: resize the image that the jpanel shows whenever jframe size changes.I have managed to do that,but the program is very ,very slow.So I believe a reason for that is that I use 'for' loops in order to change all images' icons according to the new jpanel size.
- 08-25-2012, 11:05 AM #2
Member
- Join Date
- Jun 2012
- Posts
- 49
- Rep Power
- 0
Re: How to manage files in file chooser
what about lists??
- 08-27-2012, 06:54 PM #3
Re: How to manage files in file chooser
You are storing the actual binary image data in an array? I wouldn't do this, it's very memory hungry. A folder of 5000 images would probably cause it to explodeThe problem is that I keep every picture of the directory in arrays
Yes, only store information about where the file is, not the file itself, and then load the file on demandIs there any smarter way to do that?
That's an expensive operation and becomes exponentially more expensive as the size of the image increases. There will be some limits here without a lot of ram and hardware acceleration.resize the image that the jpanel shows whenever jframe size changes
I doubt it. You can rip through a few billion iterations of a for loop in milliseconds or less. The thing that might be slowing you down is the image processing itself. If you are using pure java to do your image resizing, there are some limits on the draw performance you can get. Assuming your code is as optimized as possible and you aren't doing a lot of unnecessary work, then you probably have hit the java2d speed barrier. I would also check what you are using to do the actual resize, since some java2d methods are many times slower than others. The one I used last was:So I believe a reason for that is that I use 'for' loops in order to change all images' icons according to the new jpanel size.
Thats groovy code, not java, but the classes and techniques are the same, just add semi colons and a proper method header/returnJava Code:def scaleImage(img){ float wr = maxWindowSize.width / img.width float hr = maxWindowSize.height / img.height float scaler = wr < hr ? wr : hr BufferedImage after = new BufferedImage((int)(img.width*scaler), (int)(img.height*scaler), BufferedImage.TYPE_INT_ARGB) AffineTransform at = new AffineTransform() at.scale(scaler, scaler) AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR) after = scaleOp.filter(img, after) after }
I've read that using the AffineTransform in this way is quite a bit faster than other techniques.
I've also had success offloading the image processing to imageMagick, which for very large images (20 meg jpgs or 50 meg pngs, that kind of thing) is substantially faster. This will require that you install imageMagick though, and that breaks your app's portability to some extent.
If you profile your app, I'm guessing the two slowest parts are:
1. Resizing the image for display
2. Drawing the collection of images to the screen
Figure out which is the worst, and then see what you can do to minimize the calls to that.
- 09-02-2012, 10:02 PM #4
Member
- Join Date
- Aug 2012
- Posts
- 12
- Rep Power
- 0
Re: How to manage files in file chooser
Thank you very much for the reply.I have managed to limit the problem a little bit by changing a few things.Now I read the label and its icon currently attached to it and display it without scanning the arrays.These seems to work faster.I will check out your advice and try to implement the whole thing without using arrays for the images.Hopefully this will make thing much better :)
- 09-03-2012, 12:09 PM #5
Re: How to manage files in file chooser
You could try my Stretch Icon « Java Tips Weblog (or ShrinkIcon, linked from that page) class.
What does the subject line of this thread have to do with the question posted?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Writing zip files results in a zip file with a size, but no files when i open it
By Jaeela in forum New To JavaReplies: 11Last Post: 12-04-2011, 10:10 PM -
JFile Chooser
By karno in forum NetBeansReplies: 4Last Post: 03-17-2010, 12:47 PM -
File chooser internationalization problem
By Astghik in forum AWT / SwingReplies: 10Last Post: 01-14-2010, 06:44 PM -
[SOLVED] File chooser selecting file from directory...?
By prabhurangan in forum AWT / SwingReplies: 12Last Post: 06-18-2008, 04:08 AM -
Using File Chooser
By shaungoater in forum New To JavaReplies: 0Last Post: 03-20-2008, 12:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks