Toolkit: createImage(byte[] img) : Toolkit « java.awt « Java by API






Toolkit: createImage(byte[] img)

 
import java.awt.Image;
import java.awt.Toolkit;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public final class MainClass {

  private MainClass() {
  }

  public static Image getImage(Class relativeClass, String filename) {
    Image returnValue = null;
    InputStream is = relativeClass.getResourceAsStream(filename);
    if (is != null) {
      BufferedInputStream bis = new BufferedInputStream(is);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      try {
        int ch;
        while ((ch = bis.read()) != -1) {
          baos.write(ch);
        }
        returnValue = Toolkit.getDefaultToolkit().createImage(
            baos.toByteArray());
      } catch (IOException exception) {
        System.err.println("Error loading: " + filename);
      }
    }
    return returnValue;
  }
}

           
         
  








Related examples in the same category

1.Toolkit: addAWTEventListener(AWTEventListener listener, long eventMask)
2.Toolkit: beep()
3.Toolkit: getColorModel()
4.Toolkit: getDefaultToolkit()
5.Toolkit: getImage(URL url)
6.Toolkit: getMenuShortcutKeyMask()
7.Toolkit: getProperty(String key, String def)
8.Toolkit: getScreenResolution()
9.Toolkit: getScreenSize()
10.Toolkit: getSystemClipboard()
11.Toolkit: getSystemEventQueue()
12.Toolkit: prepareImage(Image image, int width, int height, ImageObserver observer)