Loading all images from Jar include the directory structure.

Hi I would like to puts all my images in a Jar. is it going to improve the loading speed?
I have a ImageLibary that load all the images to a hashtable and access each image by their path and filename.
I only have to input the image root directory and it will load all the images including sub-directory. If I decide to put these directories in a JAR. is this still going to work? Do all the class files has to be in the same JAR?
use getResourse()?
My current ImageLibary is like this:
public class ImagesLibary extends Component
private Hashtable imagesBank;
private Vector imagesName;
private MediaTracker tracker;
public ImagesLibary()
imagesBank = new Hashtable();
imagesName = new Vector();
tracker= new MediaTracker(this);
loadImageFile("./images");
for(int i=0; i<imagesName.size(); i++)
String key = (String)imagesName.get(i);
Image image = getToolkit().getImage(key);
tracker.addImage(image, 0);
try
tracker.waitForID(0);
catch (InterruptedException e)
System.err.println("Loading image: " + key + " fails. " + e);
imagesBank.put(key,image);
System.out.println("Loaded: " + key);
System.out.println("Total of " + imagesBank.size() + " images.");
private void loadImageFile(String dir)
File imageDir = new File(dir);
File temp[] = imageDir.listFiles();
for(int i=0; i<temp.length;i++)
if (temp.isDirectory())
loadImageFile(temp[i].getPath());
else
imagesName.add(temp[i].getPath());

is it going to improve the loading speed?depends :)
is this still going to work?some ajustments are needed... but thats done quickly.
Do all the class files has to be in the same JAR?no. but it's easier to handle.
use getResourse()?yes. don't know if u have to. but i do it this way :)
inside an application:
URL keyboardImagePath;
keyboardImagePath = (new Object()).getClass().getResource("/gfx/keyboard.gif");
Image kb=getToolkit().getImage(keyboardImagePath);inside an applet:
URL path = (new Object()).getClass().getResource( "/icons/right.gif" );
// now make the icon getting the gif from the url
ImageIcon = new ImageIcon( path );inside a hybrid:
URL keyboardImagePath;
keyboardImagePath = (new Object()).getClass().getResource("/gfx/keyboard.gif");
System.out.println("<-(application)load:"+keyboardImagePath); //if u wanna c what happens
if(keyboardImagePath==null)
     keyboardImagePath=selfRef.getClass().getResource("/gfx/keyboard.gif");
     System.out.println("<-(applet)load:"+keyboardImagePath); //if u wanna c what happens
Image kb=getToolkit().getImage(keyboardImagePath);hope that was helpfull :)

Similar Messages

  • How do I tell iphoto NOT to load ALL images from camea and iphone, only new images?

    I've bee using my MacBook Pro, iphoto and Nikon for many years. I travel alot and take many pictures, and like to keep them on the memory cards as an extra backup. All was going great on a recent trip, until one day, suddenly, when I plug camera into computer, iphoto opens (as usual) but it starts downloading ALL of the old images on the memory card instead of just the ones that have not already been imported! It takes forever when you are using a 16GB card!! Is this due to some update I installed? How do I tell iphoto not to do this?! I only want to see images not yet imported, as it used to be. I am using OS X 10.6.8 and iphoto '09 - 8.1.2  And, this same thing is happening with my iphone, and my other camera.

    iPhoto does read all images (how else can it know if it has already imported them or not) and then gives your oppertunity to import new, all or selected
    Yes it does take a bit to get all images and see what needs to be imported - I use 32 GB cards - and the other issue is that if you delete impoprted photos next time you use the card the deleted ones will be in the new list so you have to select the rest and import selected - I've found no solution to this
    LN

  • "Load All Images" appears on the bottom of the email and not on top

    Why "This message contains unloaded images"  "Load All Images" link appears on the bottom of the email in iOS Mail and not on top when opening email?
    Is that a mistake or it was put there on purpose?
    Does anybody know why?
    To scroll down any email to turn on images is a hassle for those who keep images loading option off because of data usage airtime download and spam email.

    If you have tried restart, reset, restore:
    iPhone User Guide (For iOS 4.2 and 4.3 Software)
    Then make an appointment at the Genius Bar.  if it is defective, then they will replace.

  • Problem loading image from jar file referenced by jar file

    First, I searched this one and no, I didn't find an answer. Loading images from jar files has been pretty much done to death but my problem is different. Please read on.
    I have my application, a straight up executable running from Eclipse. It uses a jar file, call it JarA. JarA launches a GUI that is located in another jar file. Call it JarB. To recap:
    My application calls JarA -> JarA loads classes from JarB -> JarB looks for images to place in a GUI it wants to show on the screen
    When JarB goes to load an image the following happens:
    java.lang.NullPointerException
         at sun.misc.URLClassPath$3.run(URLClassPath.java:316)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.misc.URLClassPath.getLoader(URLClassPath.java:313)
         at sun.misc.URLClassPath.getLoader(URLClassPath.java:290)
         at sun.misc.URLClassPath.findResource(URLClassPath.java:141)
         at java.net.URLClassLoader$2.run(URLClassLoader.java:362)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findResource(URLClassLoader.java:359)
         at java.lang.ClassLoader.getResource(ClassLoader.java:977)
         at org.cubrc.gmshell.gui.MainWin.preInit(MainWin.java:152)
         at org.cubrc.gmshell.gui.MainWin.<init>(MainWin.java:135)
    The code from JarB that loads the image looks like this:
              URL[] oSearch = {Main.class.getResource("images/")};
              URLClassLoader oLoader = new URLClassLoader(oSearch);
              imgIcon = new ImageIcon(oLoader.getResource("icon.gif"));
              imgMatchRunning = new ImageIcon(oLoader.getResource("gears.gif"));
              imgMatchStill = new ImageIcon(oLoader.getResource("gears-still.gif"));
              imgMagnify = new ImageIcon(oLoader.getResource("magnify.gif"));This looks right to me and JarB certainly has an images directory with those files. But I'm in hell right now because I don't know where to place the images to make this work or if you can even attempt to load images with a dependency chain like this.
    Any help very appreciated!

    Have you tried to move your image-files out of the jar file and place them in the sam folder as the jar-file? I think that would help.
    When you try to load the image-file you get the NullPointerException because the program tries to read a file it can't find. Remember that a jar file IS a file and not a directory.
    If you want to read somthing inside the jar-file you need to encode it first.
    Have you tried to read the jar-file with winRar. It makes it easy to add and remove files in your jar-file.

  • Loading File (not-image) from JAR ..

    Here s the jar structure i have:
    myapp.jar:
    -- package1:
    -- -- *.class
    -- file.ext
    -- image.gif
    How come i cant create inst. of File with the new File(with getClass().getResource("/file.ext").getFile()); ??
    There s no problem with loading the image, but the other file always fails .. it says that the path is wrong (i guess it s beacause file:\D:myapp.jar!\file.ext is not a 'real' file-system path). How can i load a file from jar, without using getResourdeStream, without any temp files .. I would really appreciate some help. Thanks in advance.
    Edited by: kokoroko on Dec 23, 2007 12:16 PM

    i need an inst. of the File class pointing to tht file.The only file mentioned in your OP is D:myapp.jar and you can get the corresponding File object by parsing the string returned by getFile(). Notice it will still only be a valid file if getResource() returns a file: URL - something that cannot be guaranteed.
    The point bears repeating, perhaps: D:myapp.jar!\file.ext is not a file. It is a resource (accessible via an input stream). Because it is not a file there is not - and never will be - any File object which represents its name.
    I was ( and I m still) thinking tht it could be some classpath-and-sh**t problem.The classpath has a bearing on where a resource will be looked for, but says nothing at all about what is looked for. In this case you simply cannot "load" the file (whatever "load" means) because there is no file to load.
    Finally, it is quite possible that you can do whatever it is that you are trying to do. But you have yet to say what that is: not how you want to do it (by instantiating a File, not by creating a temporary file or using an input stream), but what you want to do.

  • JAVA, sqlserver - Need to load an image from the sql server database

    hi,
    I need to load an image from the sql server database using java. I have connected to the database and getting all other records except the records for a photo (datatype = LONGVARBINARY) and Remarks (datatype = LONGVARCHAR).
    I am using java and sql server db. The photo and remarks are stored in the db. and i need to show the image and the remarks fetching them from there.
    I get the error :
    Thread-9 org.hibernate.MappingException: No Dialect mapping for JDBC type: -1
    How can I achieve this?
    Thanks,
    Gargi

    Exactly. And are you using MySQL?
    No. You are using Microsoft SQL server if I have to believe your initial post. A quick google tells me that the dialect class to use is:
    org.hibernate.dialect.SQLServerDialect

  • Load multiple images from directory?

    What is the best way to use CF to load multiple images from a
    server directory please? I have CF calling a stored procedure that
    returns an array of file names. I am using a Flex front end, and
    wonder if I should just pass the file name array to Flex and let it
    loop through and load each image into an array. Or is it possible
    from within my CFC to use the file name array to get CF to grab the
    images and then pass that image array back to Flex? If so, is there
    any advantage to either approach? TIA,
    Mic.

    You don't want to pass the binaries to Flex, you should just
    give Flex the image names and load them via HTTP.

  • Loading image from jars only once in oracle forms 10g

    Hi,
    I have an oracle forms 10g application which loads image from a jar. Every time i click on a button "A" that loads the image "image" on another button "B" in the same screen, a message is displayed in the java console "Loaded image: jar:https://+IP+/forms/java/+myjar+.jar!/image.gif". So after 10 clicks, i get the same message displayed 10 times. In the form, i've called:
    SET_CUSTOM_PROPERTY(p_object_name, 1, 'IMAGE_NAME_ON', '/'||p_image_name);My question is the following:
    - is there a way to load this image once and use it later without having to load it every time i clik on "A"? if yes, how?
    P.S.: if this thread shouldn't be posted in this forum, please redirect me to the right one.
    Thanks in advance

    Ah okay.
    I'm using the rolloverbutton.jar (RollOver Button PJC) [RolloverButton.java -> authors: Steve Button, Duncan Mills].
    Here is the part concerning the IMAGE_NAME_ON function:
    // make sure we are in rollover mode
    enableRollover();
    log("setProperty - IMAGE_NAME_ON value=" + value.toString());
    // load the requested image
    m_imageNameOn = (String) value;
    loadImage(ON,m_imageNameOn);
    // reset the currrently drawn image if needed
    setImage(ON,m_state);
    return true;where loadImage function is:
        URL imageURL = null;
        boolean loadSuccess = false;
        //JAR
        log("Searching JAR for " + imageName);
        imageURL = getClass().getResource(imageName);
        if (imageURL != null)
          log("URL: " + imageURL.toString());
          try
            m_images[which] = Toolkit.getDefaultToolkit().getImage(imageURL);
            loadSuccess = true;
            log("Image found: " + imageURL.toString());
          catch (Exception ilex)
            log("Error loading image from JAR: " + ilex.toString());
        else
          log("Unable to find " + imageName + " in JAR");
        //DOCBASE
        if (loadSuccess == false)
          log("Searching docbase for " + imageName);
          try
            if (imageName.toLowerCase().startsWith("http://")||imageName.toLowerCase().startsWith("https://"))
              imageURL = new URL(imageName);
            else
              imageURL = new URL(m_codeBase.getProtocol() + "://" + m_codeBase.getHost() + ":" + m_codeBase.getPort() + imageName);
            log("Constructed URL: " + imageURL.toString());
            try
              m_images[which] = createImage((java.awt.image.ImageProducer) imageURL.getContent());
              loadSuccess = true;
              log("Image found: " + imageURL.toString());
            catch (Exception ilex)
              log("Error reading image - " + ilex.toString());
          catch (java.net.MalformedURLException urlex)
            log("Error creating URL - " + urlex.toString());
        //CODEBASE
        if (loadSuccess == false)
          log("Searching codebase for " + imageName);
          try
            imageURL = new URL(m_codeBase, imageName);
            log("Constructed URL: " + imageURL.toString());
            try
              m_images[which] = createImage((java.awt.image.ImageProducer) imageURL.getContent());
              loadSuccess = true;
              log("Image found: " + imageURL.toString());
            catch (Exception ilex)
                    log("Error reading image - " + ilex.toString());
          catch (java.net.MalformedURLException urlex)
            log("Error creating URL - " + urlex.toString());
        if (loadSuccess == false)
          log("Error image " + imageName + " could not be located");In this case, what shall i modify?
    Thanks in advance

  • Download from ALV are all in one column including the header

    Hello All,
    We are having problems with the download of excel from ALV grid. what happens is that instead of the data dispalying in different columns, it is all in one column, including the header. what could be the problem? this only occurs in the production system but in the development and quality it is ok.
    Thanks for your help.

    Hi,
    We also used the option download to local file and it works fine. Only the button download to excel is not working as expected.

  • I have copied many photo's from another laptop to my Mac.  The older photo's are in directories with names that help me select what I need to view. I would like to have all my imported new photo's also bee added to the directory structure I have in Finder

    I have copied many photo's from another laptop to my Mac.  The older photo's are in directories with names that help me select what I need to view. I would like to have all my imported new photo's also bee added to the directory structure I have in Finder but my new photo's are all in iPhoto.  I want to use directories for storing and iPhoto for viewing.  Is this possible or do I need to have all my photo's in iPhoto??
    Mitch

    iPhoto is not a Photo Viewer. It's a Photo Manager and designed for looking after the files while you organise the Photos. It really works much better if you let it manage those files. If you use iPhoto you never go near those files because iPhoto is your start point for anything you want to do with your Photos - the point of the pplication.
    You can run iPhoto in Referenced mode, where it does not copy the files to the Library, but I caution you that you are making life a lot more difficult for yourself by doing that.
    How to, and some comments on why you shouldn't, are in this thread
    https://discussions.apple.com/thread/3062728?tstart=0
    Regards
    TD

  • I had all photos on a Windows desktop.  Got a mac laptop, installed LR5, and put all images from Windows onto an external hard drive.  When I go to import them into LR on the Mac, they are all locked.  Help, please.  Thanks

    I had all photos on a Windows desktop.  Got a mac laptop, installed LR5, and put all images from Windows onto an external hard drive.  When I go to import them into LR on the mac, they are all locked.  Help, please!

    "I plugged the external into the Mac and moved a folder of images onto the desktop.  It looks like it went from read only to not locked.  Is this possible?"
    Yes, that's exactly what happened. If you buy another drive, you could copy from your existing drive to the new and your files will be read/write. The new drive will have to be formatted as an HFS drive (that's the Mac's format). If you need to format it, you use Disk Utility which is in the Utilities folder on your Mac. Be careful with that -- it wipes out whatever is currently on the drive. Make sure you format the right drive.
    I keep all my images on an external drive, too. In fact, I have two matching drives and sync them so I always have a backup.

  • My iphone 3g wont load all comments from online newspaper. when I touch the "load more comments" button the little spinning spiral appears then nothing happens. Anyone else have this problem with some online newspapers?

    My iphone 3g wont load all comments from online newspaper. when I touch the "load more comments" button the little spinning spiral appears then nothing happens. Anyone else have this problem with some online newspapers?

    Anything?

  • How can i acces the images from jar to with in jar

    I want to now make a executable jar file which contain all class files and one jar file (which contain all images).
    before jar i use
    icon=new ImageIcon(getClass().getResource("image.gif"));
    now what can i do and it is possible that no change in the path of image icon.

    A jar inside a jar wouldn't be a good idea I don't think- you'd end up having to code around some things to get at the internal jar instead of being able to use code like "getResource()" like you posted.
    Consider an ANT task that will handle building your jar for you, if this is a logistics issue. The task can unzip the image jar and shove it in with the application jar.

  • How do I erase all images from a card in the Cannon Rebel t3

    how do I erase all images from a card in the Cannon Rebel t3

    Hello debrusso,
    I would just like to give some quick advice that you all may already know but I was just told this countless of times that I thought you all would like to know. \
    I have been told by numerous of photography professors that it is always best to try to format your camera every now and then. Because your memory card is not really deleting the photos but rather hiding it somewhere. This is a problem because it still takes space from your card. The solution to this is to FORMAT because it is one of the safest ways for your camera to erase images. It also sets up properly for your camera like new. But make sure to save your images before doing formatting. I have had many silly accidents this way. Lol.

  • Slideshow page appears to load all images at once making it very slow. Is it possible to force it to load just the required items for the immediate page / slide

    Hi Everyone
    First post and a Muse / Web Noob.
    Im building my personal website with muse ( CC and now CC 2014 ) , its quite simple with slideshows embedded inside each other and is just 4 pages in total.
    My two slideshow pages appears to load all images at once making it very slow ( plus 20 secs on my system ). Is it possible to force it to load just the required items for the immediate page / slide. It would be so much faster and would work much better in this particular situation.
    Ive built all the images and icons at the correct size so optimisation shouldn't be an issue. The whole site is only about 42mb.
    www.paradoks.co.uk
    Many thanks
    Deck

    Oh well the problem seems to have fixed itself. It seems it was either a Java or Tumblr problem because the same thing happened when I installed Chrome. It is a lot more stable now and no more crashes yay.

Maybe you are looking for

  • UDF or Mapping for removing more items

    Hi I'm in a need to implement a data validation using UDF or Graphical Mapping File has the data like ONE header record (5 fileds) and ONE item record (8 fields) as follows header:field1field2 field3 field4 field5 item:field1field2 field3 field4 fiel

  • MySql database and php code on different servers

    I created a table on a MySql database on server A. Now I'm trying to create a page to display the contents of the table. I know that the html code ( and php) is on a different server (server B). I managed to create a database connection however when

  • (winxp+oracle11g) The em page can not be opened.

    I am struggling with the OEM these days and stunned by an error. When i input https://myhostname:1158/em in ie ,it always shows that 503 Service Unavailable Servlet error: An exception occurred. The current application deployment descriptors do not a

  • Forgot my icloud password; e-mail account is deactivated.

    I recently updated my iphone 4 to iOS 7.0. I tried to update my icloud account. However, I have forgotten my password to that account and I can't reset the password because that e-mail account is deactivated. I have another apple ID I use for the itu

  • String formatting in SQL/PLSQL

    How can we format strings (Varchar) using sql/plsql? Are there any functions using which I can format varchar variables. e.g., to convert an amount 100000 to 100,000.00 .