How to load mutiple image

I'm trying to create a photo manager but I can't find a way to load multiple images onto my frame. I have a thumbnail class that makes thumbnails for an image (which is a modified version of the class ImageHolder from FilthyRichClient)
public class Thumbnails {
     private List<BufferedImage> scaledImages = new ArrayList<BufferedImage>();
private static final int AVG_SIZE = 160;
* Given any image, this constructor creates and stores down-scaled
* versions of this image down to some MIN_SIZE
public Thumbnails(File imageFile) throws IOException{
          // TODO Auto-generated constructor stub
     BufferedImage originalImage = ImageIO.read(imageFile);
int imageW = originalImage.getWidth();
int imageH = originalImage.getHeight();
boolean firstScale = true;
scaledImages.add(originalImage);
while (imageW >= AVG_SIZE && imageH >= AVG_SIZE) {
     if(firstScale && (imageW > 320 || imageH > 320)) {
          float factor = (float) imageW / imageH;
          if(factor > 0) {
          imageW = 320;
          imageH = (int) (factor * imageW);
          else {
               imageH = 320;
               imageW = (int) (factor * imageH);
     else {
          imageW >>= 1;
     imageH >>= 1;
BufferedImage scaledImage = new BufferedImage(imageW, imageH,
originalImage.getType());
Graphics2D g2d = scaledImage.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(originalImage, 0, 0, imageW, imageH, null);
g2d.dispose();
scaledImages.add(scaledImage);
* This method returns an image with the specified width. It finds
* the pre-scaled size with the closest/larger width and scales
* down from it, to provide a fast and high-quality scaled version
* at the requested size.
BufferedImage getImage(int width) {
for (BufferedImage scaledImage : scaledImages) {
int scaledW = scaledImage.getWidth();
// This is the one to scale from if:
// - the requested size is larger than this size
// - the requested size is between this size and
// the next size down
// - this is the smallest (last) size
if (scaledW < width || ((scaledW >> 1) < width) ||
(scaledW >> 1) < (AVG_SIZE >> 1)) {
if (scaledW != width) {
// Create new version scaled to this width
// Set the width at this width, scale the
// height proportional to the image width
float scaleFactor = (float)width / scaledW;
int scaledH = (int)(scaledImage.getHeight() *
scaleFactor + .5f);
BufferedImage image = new BufferedImage(width,
scaledH, scaledImage.getType());
Graphics2D g2d = image.createGraphics();
g2d.setRenderingHint(
RenderingHints.KEY_INTERPOLATION,
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(scaledImage, 0, 0,
width, scaledH, null);
g2d.dispose();
scaledImage = image;
return scaledImage;
// shouldn't get here
return null;
A loop will loop through a collection of files and pass them to the constructor of Thumbnails to create thumbnails and then set them as icon for JLabels that will be added to a JPanel, but it throws a java.lang.OutOfMemoryError at this line:
BufferedImage originalImage = ImageIO.read(imageFile);
even when there're only about 8 image files in the collection (total size 2,51MB).
I've seen other people's software that could load hundreds of photos in a matter of seconds! How do I suppose to do that? How to load mutiple images efficiently? Please help!! Thanks a lot!

another_beginner wrote:
Thanks everybody! I appreciate your help! I don't understand why but when I use a separate thread to do the job, that problem disappear. You were likely doing your image loading and thumnail creation on the Event Dispatching Thread. Among other things, this is the same thread that updates and paints your panels, frames, buttons, ect.. When a programer does something computationaly expensive on the event dispatching thread then the GUI becomes unresponsive until the computation is done.
Ideally what you want to do is load images and create thumnails on a seperate thread and update your GUI on the event dispatching thread. I supect that while you are finally doing the first item, you might now be violating the second item.
Whatever, the program seems to be pretty slow on start up 'cause it have to reload images everytime. I'm using Picasa and it can display those thumbnails almost instantly. I know that program is made by professionals. But I still want to know how.I took a look at this Picasa you mentioned. It's the photo manager from google right? You're right in that the thumnails display instantly when starting up. This is because Picasa is actually saving the thumnails, instead of creating them everytime the program starts up. It only creates the thumnails once (when you import a picture) and saves the thumnail data to " +*currentUser*+ /AppData/Local/Google/Picasa2/db3/" (at least on my computer --> Vista).
Also, if your looking for speed then for some inexplicable reason java.awt.Toolkit.getDefaultToolkit().createImage(...); is faster (sometimes much faster) than ImageIO.read(...). But there comes a price in dealing with Toolkit images. A toolkit image isn't ready for anything until it has been properly 'loaded' using one of several methods. Also, when you're done and ready for the image to be garbage collected then you need to call Image.flush() or you will eventually find yourself with an out of memory error (BufferedImages don't have this problem). Lastly, Toolkit.createImage(...) can only read image files that the older versions of java supported (jpg, png, gif, bmp) .
And, another question (or maybe I should post it in a different thread?), I can't display all thumbnails using a JPanel because it has a constant height unless I explicitly set it with setPreferredSize. Even when put in a JScrollPane, the height doesn't change so the scrollbar doesn't appear. Anyone know how to auto grow or shrink a JPanel vertically? Or I have to calculate the preferred height by myself?Are you drawing the thumnails directly on the JPanel? If so then you will indeed need to dynamically set the preferred size of the component.
If not, then presumebly your wrapping the thumnails in something like a JLabel or JButton and adding that to the panel. If so, what is the layout manager you're using for the panel?

Similar Messages

  • How to load a image after getting it with a file chooser?

    I'm still starting with JavaFX, and I simply would like to know how to load the image (e.g. png or jpg) that I selected using a FileChooser in the user interface. I can access the file normally within the code, but I'm still lost about how to load it appropriately. Every time I select a new image using the FileChooser, I should discard the previous one and consider the new one. My code is shown below:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.paint.Color;
    import javafx.scene.layout.HBox;
    import javafx.scene.control.Button;
    import javax.swing.JFileChooser;
    import javafx.scene.image.ImageView;
    import javafx.scene.image.Image;
    var chooser: JFileChooser = new JFileChooser();
    var image;
    Stage {
        title: "Image"
        scene: Scene {
            width: 950
            height: 500
            content: [
                HBox {
                    layoutX: 670
                    layoutY: 18
                    spacing: 10
                    content: [
                        Button {
                            text: "Open"
                            action: function() {
                                if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(null)) {
                                    var imageFile = chooser.getSelectedFile();
                                    println("{imageFile.getCanonicalFile()}");
                                    image = Image{
                                        width: 640
                                        url:imageFile.getAbsolutePath()
                // Image area
                Rectangle {
                    x: 10
                    y: 10
                    width: 640
                    height: 480
                    fill: Color.WHITE
                ImageView {
                    x: 10
                    y: 10
                    image: bind image
    }Thank you in advance for any suggestion to make it work. :)

    As its name implies, the url param expect... an URL, not a file path!
    So, use {color:#8000FF}url: imageFile.toURI().toURL(){color} instead.

  • How to load an image into blob in a custom form

    Hi all!
    is there some docs or how to, load am image into a database blob in a custom apps form.
    The general idea is that the user has to browse the local machine find the image, and load the image in a database blob and also in the custom form and then finally saving the image as blob.
    Thanks in advance
    Soni

    If this helps:
    Re: Custom form: Take a file name input from user.
    Thanks
    Nagamohan

  • Can anyone tell me how to load an image to custom shape in Photoshop? I can't save it as csh...

    I've made an image, as the watermark of our photos, but I can't load it to Custom Shape in PS CS4 as I can't save it as csh. Do you know how to upload an image type file that is not csh? Or how to convert the image to csh? Thanks.

    As Chris says, you can't make it into a custom shape unless you create it as a path. But you can save it as a Custom Brush (in monochrome).

  • How to load a image from database to image item in oracle 10 g form

    I have stored some images in the Database Table with BLOB datatype. Now I need to load that image in the non database image item. Please advise. Thanks.

    You need to have a print server installed to generate the pdf. Either use BI Publisher and it's desktop development tool or use FOP/Cocoon.. Adding an image with them is a little more involved..
    Thank you,
    Tony Miller
    Webster, TX
    While it is true that technology waits for no man; stupidity will always stop to take on new passengers.

  • How to load the image on to the Java applet?

    Hey,
    I need help on loading a image to java, I am using Eclipse, I have no idea what class I should use. Please help me thanks

    I found this with search problem with loading images

  • How to load an image without a gui? big problems...

    Hey guys, I usually try my best to not ask for help and figure stuff out myself. But this last week i've been having big problems with this work project.
    My goal is to load images from disk, and append them to each other to create one big image.
    The images are 0-9.jpg each file containing a number in it. then i create one big file with 4 numbers in it. called final.jpg.
    so far i can do all this, but whenever the program is finished, the application just keeps running. the program has literally gone through all the steps... i have a system.out.println printed on the last line after the main, after the class instantiation... and still it stays running.
    how do you guys load images without a gui? This program will probably be running under unix, so i can't create a (for component example)
    Panel() and media track the file load... so i'm pretty much stumped
    any help you guys can provide would be really incredibly helpfull at this point. I have searched these threads for a few hours without luck. I found only 1 real post related to my problem, but eventually they said use MediaTracker = new Mediatracker( new Panel() ); which i can't use. :(
    Thanks a lot guys.
    :D

    yeah tried doing that, didn't work either.
    UPDATE
    I FINALLY found a way...
    and here it is for others to find!
    public BufferedImage getImage(String filename) throws Exception {
    FileInputStream input = new FileInputStream( filename );
    JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder( input );
    BufferedImage image = decoder.decodeAsBufferedImage();
    return image;
    it returns an image buffer, but it's better than nothing! :)
    atleast this functions under unix.

  • How to Load External Images - Please Help!

    I have created a simple portfolio site. The buttons I created
    trigger separate frames. Could I not create a MC (Movie Clip) on
    each frame where the images now reside and then when the button is
    clicked (On "Click' Goto frame 1) for e.g. then the image would be
    loaded from an external folder named "Images" in my website?
    I am stumped as to how to set this up. Could someone please
    help me?
    Thanks

    Yes, you can do that. Which version of Flash and which
    version of Actionscript are you using?

  • How to load an image on a LAP1252 with the bootloader

    Hello--
    I have a LAP1252 that lost the flash image, consequently, when it tries to boot, the boot loader can not find anything to load. I can not find any documentation on how to use the TFTP client on the AP, can anyone point me in the right direction?
    Thank you.

    Converting a Lightweight Access Point Back to Autonomous Mode
    http://www.cisco.com/en/US/docs/wireless/access_point/conversion/lwapp/upgrade/guide/lwapnote.html#wp161272

  • How to load background image in canvas fast?

    Hi all,
    I am loading dynamic background in canvas with http path. It takes little bit time. How can i make it fast?
    Please help me.
    Thanks,
    -CK

    Make a friend with firebug &  you could find yourself from where it is getting applied.
    For the website you have given the background image it is using is [1] and it is getting set in css of body tag [2]. So Find the css at [3] and modify it OR replace [1] with other image with same file name.
    [1]   www.hanwha.com/etc/designs/hanwha/images/bg-body.jpg
    [2]
    body {
        background: url("images/bg-body.jpg") repeat-x scroll 50% 0 #FFFFFF;
        color: #757373;
        font: 14px/18px Arial,Verdana,Helvetica,sans-serif;
        margin: 0;
        min-width: 979px;
    [3]
    /etc/designs/hanwha/...../*.css

  • How to load jpeg images in database?

    I have an employees panel and it has a box to show employee's picture. Normally I double click on the box and it takes me to the folder where I have stored all employees jpeg file. I click on the one I need and then insert, it shows up on the panel and also saving the data in a table called PS_EMPLOYEE_IMAGE table.
    If I want to insert number of images at one time thru the back end like sqlplus is there a way to do it? This saves me lot of time instead of entering thru the panel. Can it be done? For example fot employee1 insert jpeg1, employee2 jpeg2 etc. DO I have to use any tool to convert these jpeg files into some other data and then insert it? Is there any pl/sql package to do it?. If some one can explain me with simple explanation I really appreciate as I am not an real oracle person. Googling for this issue says it can be done but it is not very clear in steps of doing it.

    Thanks for your help. I did exactly like what you described (see below)
    1) I created a image_file.txt file as shown below
    EMPLID|EFFDT|EFF_STATUS|IMAGE_FILE
    100000|08-FEB-2011|A|H:\SQL_Loader\George_Test.jpg
    100001|08-FEB-2011|A|H:\SQL_Loader\Eftihia_Test.jpg
    2) Then created EE_Image_Tbl.ctl file as shown below.
    OPTIONS (DIRECT=TRUE, SKIP=1)
    UNRECOVERABLE
    LOAD DATA
    APPEND
    INTO TABLE PS_EMPLOYEE_IMAGE
    FIELDS TERMINATED BY '|'
    (EMPLID
    ,EFFDT
    ,EFF_STATUS
    ,IMAGE_FILE FILLER CHAR(80)
    ,EE_IMAGE LOBFILE(IMAGE_FILE) TERMINATED BY EOF)
    3) then used the sql loader (load_ee_image.sql)
    $ sqlldr DH5M/ep5evs1@KDH5MI01 control=h:\sql_loader\EE_Image_Tbl.ctl log=h:\sql_loader\load_ee_image.log data=h:\sql_loader\image_file.txt
    SQL> --*
    SQL> commit;
    Commit complete.
    SQL> --*
    SQL> @h:\sql_loader\load_ee_image.sql;
    SQL> $ sqlldr DH5M/ep5evs1@KDH5MI01 control=h:\sql_loader\EE_Image_Tbl.ctl log=h:\sql_loader\load_ee_image.log data=h:\sql_loader\image_file.txt
    SQL> --*
    SQL> --*
    SQL> --*
    SQL> commit;
    Commit complete.
    SQL> --rollback;
    SQL> --*
    SQL> spool off
    L
    Number to skip: 1
    Errors allowed: 50
    Continuation: none specified
    Path used: Direct
    Load is UNRECOVERABLE; invalidation redo is produced.
    Table PS_EMPLOYEE_IMAGE, loaded from every logical record.
    Insert option in effect for this table: APPEND
    Column Name Position Len Term Encl Datatype
    EMPLID FIRST * | CHARACTER
    EFFDT NEXT * | CHARACTER
    EFF_STATUS NEXT * | CHARACTER
    IMAGE_FILE NEXT 80 | CHARACTER
    (FILLER FIELD)
    EE_IMAGE DERIVED * EOF CHARACTER
    Dynamic LOBFILE. Filename in field IMAGE_FILE
    SQL*Loader-418: Bad datafile datatype for column EE_IMAGE
    This is becasue my image datatype can be declared as LONG RAW dara type thru my application.
    When I created a table with image datatype as BLOB it worked.
    But I want to insert into the existing table where image is declared as LONG RAW. How to insert jpeg into this field. Do I have to convert anything? Thx.
    Edited by: user5846372 on Feb 8, 2011 1:18 PM
    Edited by: user5846372 on Feb 8, 2011 2:16 PM

  • How to load big images in Java?

    Hello all,
    is there any possibility to load a big images about 200-500 Mb with Java Graphics API ?
    This code throws OutOfMemory Exception.
            try {
                BufferedImage img = ImageIO.read(new File("testpic1.bmp"));
                int w = img.getWidth(null);
                int h = img.getHeight(null);
                bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                Graphics g = bi.getGraphics();
                g.drawImage(img, 0, 0, null);
            } catch (IOException e) {
                System.out.println("Image could not be read");
                System.exit(1);
      protected void paintComponent(Graphics g) {
       g2D.drawImage(bi, null, 0, 0);
      }I can't extend memory for the JVM because of my requirement. So I have to load a picture partly as user access to it.
    I am very thankful for every idea.

    I try to read an image like this:
    The size of the image is 10000x4000
    How can I read from Buffer 6000-5700 = 300 for width and 3000-2700 = 300 for heigth?
    If I do it like that
    bi = new BufferedImage(6000, 3000, BufferedImage.TYPE_INT_ARGB);
    I read more, than I need.
    Is there somthing like
    bi = new BufferedImage(5700, 2700, 6000, 3000, BufferedImage.TYPE_INT_ARGB);
    ??

  • How to load an image from local disk?

    Hi!
    I have spent hours on the net searching for an example, that
    could
    show me how could I make a flex script that user could browse
    (like fileReference.browse() ) for a
    file (picture) and then show this picture in the browser (so
    the source of some existing picture would change).
    I found only multiple solutions on how to upload a picture,
    but
    that is not the thing I wanna do. I want a user to load a
    picture from
    his disk and simply to be seen in a browser (on a page).
    I tried programming it alone, but the FileReference class has
    no attribute path or similar, that I could use for source of my
    image.
    Please help, I need to do this urgently.
    Thank you very very much
    Gus

    OK, I tried without FileReference, simply by changing String
    variable of the source path when calling image.load(path), but it
    works ONLY FOR REMOTE pictures (online), I also tried with
    [Bindable]
    [Embed(source="C:/somePicture.jpg")]
    public var _img0:Class;
    , but it appears that you CANNOT CHANGE THE PATH DOURING
    EXECUTION (dinamically)
    So please, someone?
    Is it even possible to do that?
    I could try uploading picture and then downloading, but why
    would I need a server side if I don't need it...
    Help

  • How to Load an image into buffered image then drawString()?

    HELP , i need to load image for the background called noise.png
    I want to load the noise.png as the background of the new generated image .
    How suppose that i can do that ?
    This is my code with a Black color background
    public static String createViverificationImageAtPath(String path,int width, int height) throws IOException {
            String out = "";
            java.awt.image.BufferedImage bi = new java.awt.image.BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
            bi.setRGB();
            String viver = (int)((float)Math.random() * 100000) + "";
            viver = generate.getRandomRomanLetter(false) + viver + generate.getRandomRomanLetter(false);
            Graphics2D g2d =  bi.createGraphics();
           // g2d.setColor(Color.blue);
            g2d.setBackground(Color.yellow);
            g2d.drawString(viver,3,height - 5);
            g2d.drawLine(0,height,width,0);
            ImageIO.write(bi,"jpeg",new File(path));
            return viver;
        }

    ImageIO.load()
    you know, the opposite of save?

  • How to load .jpeg images dynamically

    Hi all,
    I am only perfect with basics of AS3 and flash. I need AS3
    code or a basic example/tutorial for loading of .jpeg images into
    flash from database.I had searched through google, but, any of the
    example won't match.
    Please, If anyone has their ideas, atleast send me the
    algorithm for your idea, so that i can try by implementing the
    idea.
    I think, once again when I open this topic, i will be
    getting my requirement.
    Thanks a lot in advance. Reply me soon.. It is urgent..
    Srihari.Ch

    The loading is easy:
    var l:Loader = new Loader();
    l.load( new URLRequest( "
    http://www.adobe.com/devnet/images/214x74/adc_lockup.jpg"
    addChild( l )
    But the database part, well... what kind of database did you
    have in mind?
    Store the images on disk and just have their path in the
    database or have the images as blob in the database. Are you
    looking for serverside script and SQL aswell? It's a question with
    a lot of different answers...

Maybe you are looking for