ImageLoader.java

/*
 * Copyright © 2012 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners.
 * See LICENSE.TXT for license information.
 */
package com.nokia.example.racer.helpers;

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Image;

/*
 * Util class to load images.
 */
public class ImageLoader {

    private static ImageLoader self;

    private ImageLoader() {
    }

    public static ImageLoader getInstance() {
        if (self == null) {
            self = new ImageLoader();
        }
        return self;
    }

    /**
     * Loads the image in the given path
     *
     * @param imagepath Path to the image
     * @return Loaded image
     * @throws IOException
     */
    public Image loadImage(String imagepath)
        throws IOException {
        InputStream in = this.getClass().getResourceAsStream(imagepath);
        Image image = Image.createImage(in);
        return image;
    }
}