public static BufferedImage zoom(BufferedImage image,float factor) {
      AffineTransform transform=AffineTransform.getScaleInstance(factor,factor);
      BufferedImageOp op=new AffineTransformOp(transform,AffineTransformOp.TYPE_BILINEAR);
      BufferedImage filteredImage=new BufferedImage(
            (int)(image.getWidth()*factor),
            (int)(image.getHeight()*factor),
            image.getType());
      op.filter(image, filteredImage);
      return filteredImage;
   }

解决方案 »

  1.   

    BufferedImage b;// you need to assign/initialize the memory to b;
    // this makes your image buffer not null.
    // or BufferedImage a will be null.Image img = getImage("picture.gif");
    int width = img.getWidth(this);
    int height = img.getHeight(this);// 1. create the image buffer for b
    b = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);// 2. draw the content to image buffer
    Graphics2D bContext = b.createGraphics();
    bContext.drawImage(img, 0, 0, null);
    BufferedImage a = (BufferedImage)b.getScaledInstance(100,100,SCALE_SMOOTH);