javauis/eswt_qt/com.nokia.swt.extensions/extensions/org/eclipse/swt/internal/extension/ImageUtil.java
changeset 78 71ad690e91f5
parent 26 dc7c549001d5
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
    11 
    11 
    12 package org.eclipse.swt.internal.extension;
    12 package org.eclipse.swt.internal.extension;
    13 
    13 
    14 import org.eclipse.swt.graphics.Device;
    14 import org.eclipse.swt.graphics.Device;
    15 import org.eclipse.swt.graphics.Image;
    15 import org.eclipse.swt.graphics.Image;
       
    16 import org.eclipse.swt.graphics.Point;
    16 import org.eclipse.swt.graphics.Internal_GfxPackageSupport;
    17 import org.eclipse.swt.graphics.Internal_GfxPackageSupport;
       
    18 import java.io.InputStream;
    17 
    19 
    18 public final class ImageUtil{
    20 public final class ImageUtil{
    19     
    21     
    20     public static Image createImageWithoutSecurityCheck(Device device, String filename) {
    22     public static Image createImageWithoutSecurityCheck(Device device, String filename) {
    21         return Internal_GfxPackageSupport.createImageWithoutSecurityCheck(device, filename);
    23         return Internal_GfxPackageSupport.createImageWithoutSecurityCheck(device, filename);
    22      }
    24     }
       
    25     
       
    26     /**
       
    27      * @deprecated Use createImageFromTheme(Device device, String name) instead.
       
    28      * @param device
       
    29      * @param id
       
    30      * @return
       
    31      */
       
    32     public static Image createImageFromTheme(Device device, int id) {
       
    33         return null;
       
    34     }
       
    35     
       
    36     /**
       
    37      * Creates an eSWT Image from a theme icon.
       
    38      * Example:
       
    39      *      Image image = ImageUtil.createImageFromTheme(display, "qtg_fr_rocker_normal_c");
       
    40      * @param device
       
    41      * @param name
       
    42      * @return
       
    43      */
       
    44     public static Image createImageFromTheme(Device device, String name) {
       
    45         Image res = null;
       
    46         int iconHandle = org.eclipse.swt.internal.qt.OS.HbIcon_new(name);
       
    47         org.eclipse.swt.internal.qt.graphics.Image cgImage = 
       
    48             org.eclipse.swt.internal.qt.graphics.Image.createImageFromPixmap(
       
    49                     org.eclipse.swt.internal.qt.OS.HbIcon_pixmap(iconHandle));
       
    50         res = Internal_GfxPackageSupport.new_Image(device, cgImage);
       
    51         org.eclipse.swt.internal.qt.OS.HbIcon_delete(iconHandle);
       
    52         return res;
       
    53     }
       
    54     
       
    55     /**
       
    56      * Returns the bounds of an Image without creating an actual Image instance.
       
    57      * Useful if there's a need to check the bounds of large collection of images
       
    58      * to choose one that gets initialized.
       
    59      *
       
    60      * For bitmap files the function returns the size of the bitmap. For SVG
       
    61      * the default size of the image is returned.
       
    62      *
       
    63      * Note that contents of the file are loaded to memory even when using
       
    64      * this function. If you are going to load the image anyway, using this 
       
    65      * function is not efficient.
       
    66      *
       
    67      * @param device The device to use when loading
       
    68      * @param filename Filename from where to read the image data from. File is loaded from the classpath, not from the file system. 
       
    69      * @return Size of the image
       
    70      * @throws IOException if image cannot be loaded
       
    71      */
       
    72     public static Point getImageSize(Device device, String filename) {
       
    73         return Internal_GfxPackageSupport.getImageSize(device, filename);
       
    74     }
       
    75     
       
    76     /**
       
    77      * Returns the bounds of an Image without creating an actual Image instance.
       
    78      * Useful if there's a need to check the bounds of large collection of images
       
    79      * to choose one that gets initialized.
       
    80      *
       
    81      * For bitmap files the function returns the size of the bitmap. For SVG
       
    82      * the default size of the image is returned.
       
    83      *
       
    84      * Note that contents of the file are loaded to memory even when using
       
    85      * this function. If you are going to load the image anyway, using this 
       
    86      * function is not efficient.
       
    87      *
       
    88      * @param is The InputStream from where to read the image data from
       
    89      * @return Size of the image
       
    90      * @throws IOException if image cannot be loaded
       
    91      */
       
    92     public static Point getImageSize(InputStream stream) {
       
    93         return Internal_GfxPackageSupport.getImageSize(stream);
       
    94     }
    23 }
    95 }