javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/org/eclipse/swt/internal/qt/graphics/ImageLoader.java
changeset 78 71ad690e91f5
parent 21 2a9601315dfc
child 80 d6dafc5d983f
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
    11 package org.eclipse.swt.internal.qt.graphics;
    11 package org.eclipse.swt.internal.qt.graphics;
    12 
    12 
    13 import java.io.*;
    13 import java.io.*;
    14 
    14 
    15 import org.eclipse.swt.graphics.Point;
    15 import org.eclipse.swt.graphics.Point;
       
    16 import org.eclipse.swt.graphics.Device;
    16 
    17 
    17 /**
    18 /**
    18  * ImageLoader is class for image loading from various data formats.
    19  * ImageLoader is class for image loading from various data formats.
    19  *
    20  *
    20  *
    21  *
   228     public void setLoadSize(int width, int height) {
   229     public void setLoadSize(int width, int height) {
   229     	OS.imageLoader_setLoadSize(handle, width, height);
   230     	OS.imageLoader_setLoadSize(handle, width, height);
   230     }
   231     }
   231 
   232 
   232     /**
   233     /**
       
   234      * Returns the bounds of an Image without creating an actual Image instance.
       
   235      *
       
   236      * @param is The InputStream from where to read the image data from
       
   237      * @return Bounds of the image
       
   238      */
       
   239     public static Point getImageSize(InputStream is) throws IOException {
       
   240 
       
   241         if (is == null) {
       
   242             throw new NullPointerException("InputStream is null");
       
   243         }
       
   244 
       
   245         int bytesAvailable = is.available(); // may throw IOException
       
   246 
       
   247         if (bytesAvailable == 0) {
       
   248             throw new IllegalArgumentException("Empty file");
       
   249         }
       
   250 
       
   251         byte [] data = new byte[bytesAvailable];
       
   252         
       
   253         if (is.read(data, 0, data.length) != bytesAvailable) {
       
   254             throw new IOException("Could not load data from InputStream");
       
   255         }
       
   256         
       
   257         return OS.imageLoader_getImageSize(data);
       
   258     }
       
   259 
       
   260     /**
   233      * Private helper to check the state of the current instance.
   261      * Private helper to check the state of the current instance.
   234      */
   262      */
   235     private void checkState() {
   263     private void checkState() {
   236     	Utils.validateUiThread();
   264     	Utils.validateUiThread();
   237         if (disposed) {
   265         if (disposed) {