public class NetImg implements ImageObserver{
  boolean     m_gotDim=false;
  int         m_contentLength=0;
  Dimension   m_dim=new Dimension(-1,-1);
  public NetImg(String imgUrl){
    Toolkit toolkit=Toolkit.getDefaultToolkit();
    URL url=null;
    try{
      url=new URL(imgUrl);
      URLConnection connection=url.openConnection();
      String contentType=connection.getContentType();
      m_contentLength=connection.getContentLength();
      if(contentType.startsWith("image")){
        Image img=toolkit.getImage(url);
        for(int i=0;i<1000;i++){
          int width=img.getWidth(this);
          int height=img.getHeight(this);
          if((width>0)&&(height>0)){
            m_dim.width=width;
            m_dim.height=height;
            m_gotDim=true;
            return;
          }
          Thread.sleep(20);
        }
      }
      m_gotDim=true;
    }catch(Exception e){System.out.println(e);System.out.println(imgUrl);};
  }
  public int getSize(){
    return m_contentLength;
  }
  public Dimension getDim(){
    return m_dim;
  }
  public boolean imageUpdate(Image img, int info, int x, int y, int width,
int height){
    if((width>0)&&(height>0))
      return true;
    else if(m_gotDim)
      return true;
    else
      return false;
  }

}


I hope this help.

Jim



>Anyone knows how can I get the GIF or JPEG width ?
>
>thanks
>anderson
>
>===========================================================================
>To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
>Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to