Search in sources :

Example 1 with FileEncodedImage

use of com.codename1.components.FileEncodedImage in project CodenameOne by codenameone.

the class FileEncodedImage method create.

/**
 * Creates an encoded image that maps to a local file thus allowing to
 * seamlessly fetch files as needed. This only works reasonably well for very small
 * files. This version of the method creates the file from an input stream
 *
 * @param fileName the name of the file
 * @param i input stream from which to create the file
 * @param width the width of the file or -1 if unknown (notice that this will improve performance)
 * @param height the height of the file or -1 if unknown (notice that this will improve performance)
 * @return image that will load the file seamlessly
 */
public static FileEncodedImage create(String fileName, InputStream i, int width, int height) throws IOException {
    EncodedImage e = EncodedImage.create(i);
    FileEncodedImage f = new FileEncodedImage(fileName, width, height, true);
    f.data = e.getImageData();
    OutputStream o = FileSystemStorage.getInstance().openOutputStream(fileName);
    o.write(f.data);
    o.close();
    return f;
}
Also used : OutputStream(java.io.OutputStream) EncodedImage(com.codename1.ui.EncodedImage)

Aggregations

EncodedImage (com.codename1.ui.EncodedImage)1 OutputStream (java.io.OutputStream)1