zoukankan      html  css  js  c++  java
  • 将Image转化为BufferImage

    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;
    }

    }

  • 相关阅读:
    zzuli-2259 matrix
    【vlan之四种方式链路认证组网]
    【ppp-chap,pap,mp,mp-group】
    【ospf-基础配置】
    【rip-基础配置】
    【静态路由】
    【nat---basic,napt,easy ip】
    【acl-访问控制列表】
    【交换接口的-绑定-认证-隔离】
    【vlan-给予mac地址认证】
  • 原文地址:https://www.cnblogs.com/mafeng/p/4460617.html
Copyright © 2011-2022 走看看