コード例 #1
0
  /**
   * @param s
   * @param fill
   * @return
   */
  public Bitmap getImage(String s, int fill) {
    // check image has for image
    Bitmap image = images.get(s);
    if (image != null) {
      return image;
    }
    // check xobjects for stream
    Stream st = (Stream) library.getObject(xobjects, s);
    if (st == null) {
      return null;
    }
    // return null if the xobject is not an image
    if (!st.isImageSubtype()) {
      return null;
    }
    // lastly return the images.
    try {
      image = st.getImage(fill, this, true);
    } catch (Exception e) {
      logger.log(Level.FINE, "Error getting image by name: " + s, e);
    }

    if (image != null && !st.isImageMask()) {
      images.put(s, image);
    }
    return image;
  }
コード例 #2
0
  public void dispose(boolean cache) {
    /*
    System.out.println("Resources.dispose()  cache: " + cache);
    try { throw new RuntimeException("MARK"); } catch(Exception e) {
        StackTraceElement[] ste = e.getStackTrace();
        for(int i = 1; i < Math.min(20,ste.length); i++)
            System.out.println("  " + ste[i].getClassName() + "." + ste[i].getMethodName() + " : " + ste[i].getLineNumber());
    }
    */
    // remove all images.
    if (images != null) {
      Enumeration shapeContent = images.elements();
      // find all shapes that are images
      while (shapeContent.hasMoreElements()) {
        Object image = shapeContent.nextElement();
        if (image instanceof Bitmap) {
          Bitmap tmp = (Bitmap) image;
          tmp.recycle();
        }
      }
      // clear hash to free max memory
      images.clear();
    }
    // NOTE: Make sure not to clear fonts, color spaces, pattern,
    // or extGStat's as this hold reverences to object not the actual
    // object. The only images contain object with a lot of memory

    if (xobjects != null) {
      Enumeration xobjectContent = xobjects.elements();
      while (xobjectContent.hasMoreElements()) {
        Object tmp = xobjectContent.nextElement();
        if (tmp instanceof Stream) {
          Stream stream = (Stream) tmp;
          stream.dispose(cache);
        }
        if (tmp instanceof Reference) {
          Object reference = library.getObject((Reference) tmp);
          if (reference instanceof Form) {
            Form form = (Form) reference;
            form.dispose(cache);
          }
          if (reference instanceof Stream) {
            Stream stream = (Stream) reference;
            stream.dispose(cache);
          }
        }
      }
    }
  }