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

📄 bufferedimagebuilder.java

📁 一个简单的绘图程序
💻 JAVA
字号:
package grapro;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
/** * @author Anthony Eden */
public class BufferedImageBuilder {
	    private static final int DEFAULT_IMAGE_TYPE = BufferedImage.TYPE_INT_RGB;
	    public BufferedImage bufferImage(Image image)
	   {        return bufferImage(image, DEFAULT_IMAGE_TYPE);    }
	    public BufferedImage bufferImage(Image image, int type)
	   {        
	   BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
	   Graphics2D g = bufferedImage.createGraphics();
	   g.drawImage(image, null, null);
	   waitForImage(bufferedImage);
	   return bufferedImage;    
	   }
	   private void waitForImage(BufferedImage bufferedImage)
	   {        
	   final ImageLoadStatus imageLoadStatus = new ImageLoadStatus();
	      bufferedImage.getHeight(new ImageObserver()
	      {
	      	public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
	      	 {
	      	 	if (infoflags == ALLBITS)
	      	 	 {imageLoadStatus.heightDone = true;
	      	 	  return true;
	      	 	 }
	      	 	 return false;
	      	 }
	      });
	     bufferedImage.getWidth(new ImageObserver()
	     {
	     	public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
	     	 {
	     	 	if (infoflags == ALLBITS) 
	     	 	{imageLoadStatus.widthDone = true;
	     	 	 return true;
	     	 	}
	     	 	return false;
	     	 }
	    });
	      while (!imageLoadStatus.widthDone && !imageLoadStatus.heightDone)
	      { try {Thread.sleep(300);}
	        catch (InterruptedException e) { }
	      }    
	    }
	   class ImageLoadStatus 
	   {
	   	public boolean widthDone = false;
	   	public boolean heightDone = false;    
	   	}
	   	
	  }

⌨️ 快捷键说明

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