⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagelayer.java

📁 geotools的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
					return;
        }
        int[] data = new int[(height*width)];
				if(DEBUG)System.out.println("copy "+x+" "+y);
				if(DEBUG)System.out.println("copy "+imdata.length+" "+data.length);
				if(DEBUG)System.out.println("copy "+(y*imwidth+x)+" "+((y+height)*imwidth+x));
				if(((y+height)*imwidth+x)>imdata.length)height--;
				for(int i=0;i<height;i++){

				//if(DEBUG)System.out.println(""+((y+i)*imwidth+x)+","+(i*width)+","+(width));
					System.arraycopy(imdata,(y+i)*imwidth+x,data,i*width,width);
				}
        /*PixelGrabber pg = new PixelGrabber(
                                           this.image,
                                           x,
                                           y,
                                           width,
                                           height,
                                           data,
                                           0,
                                           width);
        if(DEBUG)System.out.println("IL-->about to grab");
        try {
          pg.grabPixels();
        } catch (InterruptedException e) {
          System.err.println("IL-->interrupted waiting for pixels!");
          return;
        }
        if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
          System.err.println("IL-->image fetch aborted or errored, status="+pg.getStatus());
          return ;
        }
				*/
        source = new MemoryImageSource(width,height,data,0,width);
        Image image2 = obs.createImage(source);
        drawn=g.drawImage(image2,origin[0],origin[1]-gh,gw,gh,obs);
        if(DEBUG)System.out.println("IL ("+this+") -->5.1 drawn="+drawn+" "+this.image);
        image2=null;
      }
    }
  }

  protected byte[] getImageData(java.io.InputStream instr) {
    byte[] res = null;
    try {
      java.io.ByteArrayOutputStream outstr = new java.io.ByteArrayOutputStream();
      byte[] buff = new byte[16000];
      int cnt = instr.read(buff);
      while (cnt != -1) {
        outstr.write(buff, 0, cnt);
        cnt = instr.read(buff);
      } // end of while (cnt != -1)
      //    instr.close();
      res = outstr.toByteArray();
      outstr.close();
    } catch (java.io.IOException e) {
      res = null;
    } // end of try-catch
    
    return res;
  }

  public void run() {
    setStatus(Layer.PENDING);
    if(DEBUG) System.out.println("IL--> Request image " + this.src + " " + bbox);

    // Start getting the image.  If the image is .gif or .jpg then
    // use default java tools otherwise use Jimi class
    String type="";
		URLConnection con; 
		Toolkit tk = Toolkit.getDefaultToolkit();
    if (src != null) {
			try{
        con = this.src.openConnection();
        type = con.getContentType();
			}catch(java.io.IOException ioe){
        System.err.println("IL--> problem opening connection");
				return;
			}

			if((type!=null) && type.startsWith("image")){
        if(type.trim().endsWith("gif")
          || type.trim().endsWith("jpeg")){
						this.image = tk.getImage(this.src);
						if(DEBUG)System.out.println("New fetch ?");
				}else{
					this.image = Jimi.getImage(this.src,type);
				}
			}else{
				if(type.startsWith("text")){
					try{
						String line;
						BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
						while((line=in.readLine())!=null){
							System.err.println("IL("+this+"):"+line);
							setStatus(Layer.ERRORED);
						}
						return;
					}catch(IOException e){
						System.err.println("IL("+this+"):"+e);
						setStatus(Layer.ERRORED);
						return;
					}
				}
			}
    } // end of if (src != null)
    if (src_stream != null) {
			System.out.println("going with stream ");
      byte[] img_data = getImageData(src_stream);
      // here we can put condition for creating
      // image or not for some reason
      this.image = tk.createImage(img_data);
    } // end of if (src_stream != null)
    

    //    if(DEBUG)System.out.println(
    //            "IL--> Image Width="+this.image.getWidth(obs));
		if(DEBUG)System.out.println("adding image to tracker "+myID);
    tracker.addImage(this.image,++myID);
    try {
      if(DEBUG)System.out.println("IL ("+this+")-->Waiting ");
      while((tracker.statusID(myID,true)&tracker.LOADING)!=0){
        if(getStatus()==Layer.ABORTED){
					if(DEBUG)System.out.println("Abort - removing image");
          tracker.removeImage(this.image,myID);
          break;
        }
        tracker.waitForID(myID,500);
        if(DEBUG)System.out.println("IL ("+this+")-->status loop, status="+tracker.statusID(myID,true)+" myID="+myID);

      }
      int state=tracker.statusID(myID,true);
			if(DEBUG)System.out.println("finished load status "+state);
			if(state==tracker.COMPLETE)System.out.println("Il: Complete");
			if(state==tracker.ABORTED)System.out.println("Il: ABORTED");
			if(state==tracker.ERRORED)System.out.println("Il: ERRORED");
			if(state==tracker.LOADING)System.out.println("Il: LOADING");
      if((state&tracker.COMPLETE) == tracker.COMPLETE){
				int height = image.getHeight(obs);
				int width = image.getWidth(obs);
				imwidth=width;
        imdata = new int[(height*width)];
        PixelGrabber pg = new PixelGrabber(
                                           this.image,
                                           0,
                                           0,
                                           width,
                                           height,
                                           imdata,
                                           0,
                                           width);
        if(DEBUG)System.out.println("IL-->about to grab");
        try {
          pg.grabPixels();
        } catch (InterruptedException e) {
          System.err.println("IL-->interrupted waiting for pixels!");
          return;
        }
        if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
          System.err.println("IL-->image fetch aborted or errored, status="+pg.getStatus());
					setStatus(Layer.ABORTED);
          return ;
        }
        source = new MemoryImageSource(width,height,imdata,0,width);
        image = obs.createImage(source);
        if(DEBUG)System.out.println("IL ("+this+")-->Image Ready ");
        setStatus(Layer.COMPLETED);
        //setStatus() triggers a LayerChangedEvent.
      }else if(state == tracker.ABORTED){
        setStatus(Layer.ABORTED);
        if(DEBUG)System.out.println("IL ("+this+")-->Image Aborted ");
      }else {
				Exception e = new Exception();
				e.printStackTrace();
        setStatus(Layer.ERRORED);
        if(DEBUG)System.out.println("IL ("+this+")-->Image Error ");
      }

    } catch (InterruptedException e) {
      System.out.println("IL ("+this+")-->Interupted ");
      setStatus(Layer.ERRORED);
      return;
    }
    //} else { // not image
    //    if (DEBUG) System.out.println("Image unavailable, con type= "+type);
    //}
    //setStatus(Layer.ERRORED);
  } 
}
/*
 * Changes in file:
 *
 * $Log: ImageLayer.java,v $
 * Revision 1.34.4.1  2002/01/15 17:10:15  ianturton
 * fixed bug (503887) where Image was deleted before it became loaded
 *
 * Revision 1.34  2001/12/20 15:27:57  ianturton
 * various fixes and small mods to make WMSExample actually run. Can now
 * display an image if you remember to choose gif or jpg as output. Still
 * crashes if you zoom in.
 *
 * Revision 1.33  2001/12/11 11:35:01  ianturton
 * improved painting of cliped images.
 *
 * Revision 1.32  2001/12/11 10:35:00  ianturton
 * readded support of png/tiff images
 *
 * Revision 1.30  2001/12/07 11:01:33  ianturton
 * Removed unnecessary calls for updates in paint method
 *
 * Revision 1.29  2001/11/22 11:00:01  kobit
 * Separated image data loading from image creating and some comments added
 *
 * Revision 1.28  2001/11/21 13:48:19  kobit
 * Added support for creating ImageLayer with InputStream as image data source and full support for downaloding map data from WMS with jprotocols package
 *
 *
 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -