java.awt.image.BufferedImage.getType()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(631)

本文整理了Java中java.awt.image.BufferedImage.getType()方法的一些代码示例,展示了BufferedImage.getType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedImage.getType()方法的具体详情如下:
包路径:java.awt.image.BufferedImage
类名称:BufferedImage
方法名:getType

BufferedImage.getType介绍

[英]Returns the image type. If it is not one of the known types, TYPE_CUSTOM is returned.
[中]返回图像类型。如果不是已知类型之一,则返回类型\自定义。

代码示例

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

private static BufferedImage scaleDown(BufferedImage sourceImage, int targetWidth, int targetHeight) {
  int sourceWidth  = sourceImage.getWidth();
  int sourceHeight = sourceImage.getHeight();
  BufferedImage targetImage = new BufferedImage(targetWidth, targetHeight, sourceImage.getType());
  Graphics2D g = targetImage.createGraphics();
  g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g.drawImage(sourceImage, 0, 0, targetWidth, targetHeight, 0, 0, sourceWidth, sourceHeight, null);
  g.dispose();
  return targetImage;
}

代码示例来源:origin: ivan-vasilev/neuralnetworks

private BufferedImage resize(BufferedImage input, int targetWidth, int targetHeight)
  {
    BufferedImage result = new BufferedImage(targetWidth, targetHeight, input.getType());

    Graphics2D g = result.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.drawImage(input, 0, 0, targetWidth, targetHeight, null);
    g.dispose();

    return result;
  }
}

代码示例来源:origin: stackoverflow.com

public static BufferedImage copyImage(BufferedImage source){
  BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), source.getType());
  Graphics g = b.getGraphics();
  g.drawImage(source, 0, 0, null);
  g.dispose();
  return b;
}

代码示例来源:origin: jphp-group/jphp

@Override
  public PImage __clone(Environment env, TraceInfo trace) {
    BufferedImage copyOfImage =
        new BufferedImage(getWidth(), getHeight(), image.getType());
    Graphics g = copyOfImage.createGraphics();
    g.drawImage(image, 0, 0, null);

    return new PImage(env, copyOfImage);
  }
}

代码示例来源:origin: net.thucydides/thucydides-core

protected ResizableImage resizeImage(int width, int targetHeight, BufferedImage image) throws IOException {
  try {
    int imageType = (image.getType() > 0) ? image.getType() : BufferedImage.TYPE_4BYTE_ABGR;
    BufferedImage resizedImage = new BufferedImage(width, targetHeight, imageType);
    fillWithWhiteBackground(resizedImage);
    resizedImage.setData(image.getRaster());
    return new ResizedImage(resizedImage, screenshotFile);
  } catch (Throwable e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: igniterealtime/Smack

/**
 * A convenience method for getting ARGB pixels from an image. This tries to avoid the performance
 * penalty of BufferedImage.getRGB unmanaging the image.
 * @param image   a BufferedImage object
 * @param x       the left edge of the pixel block
 * @param y       the right edge of the pixel block
 * @param width   the width of the pixel array
 * @param height  the height of the pixel array
 * @param pixels  the array to hold the returned pixels. May be null.
 * @return the pixels
 * @see #setRGB
 */
public int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
  int type = image.getType();
  if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB)
    return (int[]) image.getRaster().getDataElements(x, y, width, height, pixels);
  return image.getRGB(x, y, width, height, pixels, 0, width);
}

代码示例来源:origin: haraldk/TwelveMonkeys

pParam.getDestinationType() != null && pParam.getDestinationType().getBufferedImageType() != image.getType())) {
BufferedImage destination = getDestination(pParam, getImageTypes(pIndex), getWidth(pIndex), getHeight(pIndex));
Graphics2D g = destination.createGraphics();
try {
  g.setComposite(AlphaComposite.Src);
  g.drawImage(image, 0, 0, null);

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

private void getImagePixels() {
  int w = image.getWidth();
  int h = image.getHeight();
  int type = image.getType();
  if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR)) {
    BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = temp.createGraphics();
    g.drawImage(image, 0, 0, null);
    image = temp;
  }
  pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
}

代码示例来源:origin: jphp-group/jphp

@Signature
public PImage resize(int width, int height) {
  BufferedImage image = new BufferedImage(width, height, this.image.getType());
  Graphics2D gc = image.createGraphics();
  gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  gc.drawImage(this.image, 0, 0, width, height, null);
  gc.dispose();
  this.image = image;
  return this;
}

代码示例来源:origin: stackoverflow.com

public static BufferedImage getScaledImage(BufferedImage image, int width, int height) throws IOException {
  int imageWidth  = image.getWidth();
  int imageHeight = image.getHeight();

  double scaleX = (double)width/imageWidth;
  double scaleY = (double)height/imageHeight;
  AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
  AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);

  return bilinearScaleOp.filter(
    image,
    new BufferedImage(width, height, image.getType()));
}

代码示例来源:origin: net.serenity-bdd/core

protected ResizableImage resizeImage(int width, int targetHeight, BufferedImage image) throws IOException {
  try {
    int imageType = (image.getType() > 0) ? image.getType() : BufferedImage.TYPE_4BYTE_ABGR;
    BufferedImage resizedImage = new BufferedImage(width, targetHeight, imageType);
    fillWithWhiteBackground(resizedImage);
    resizedImage.setData(image.getRaster());
    return new ResizedImage(resizedImage, screenshotFile);
  } catch (Throwable e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: igniterealtime/Smack

/**
 * A convenience method for setting ARGB pixels in an image. This tries to avoid the performance
 * penalty of BufferedImage.setRGB unmanaging the image.
 * @param image   a BufferedImage object
 * @param x       the left edge of the pixel block
 * @param y       the right edge of the pixel block
 * @param width   the width of the pixel array
 * @param height  the height of the pixel array
 * @param pixels  the array of pixels to set
 * @see #getRGB
 */
public void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
  int type = image.getType();
  if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB)
    image.getRaster().setDataElements(x, y, width, height, pixels);
  else
    image.setRGB(x, y, width, height, pixels, 0, width);
}

代码示例来源:origin: libgdx/libgdx

splitImage = new BufferedImage(region.width, region.height, page.getType());
BufferedImage paddedImage = new BufferedImage(splitImage.getWidth() + padding * 2, splitImage.getHeight() + padding * 2,
  page.getType());
Graphics2D g2 = paddedImage.createGraphics();
g2.drawImage(splitImage, padding, padding, null);
g2.dispose();
return paddedImage;

代码示例来源:origin: shopizer-ecommerce/shopizer

/**
 * Simple resize, does not maintain aspect ratio
 * @param image
 * @param width
 * @param height
 * @return
 */

public static BufferedImage resize(BufferedImage image, int width, int height) {
  int type = image.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : image
      .getType();
  BufferedImage resizedImage = new BufferedImage(width, height, type);
  Graphics2D g = resizedImage.createGraphics();
  g.setComposite(AlphaComposite.Src);
  g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
      RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  g.setRenderingHint(RenderingHints.KEY_RENDERING,
      RenderingHints.VALUE_RENDER_QUALITY);
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
      RenderingHints.VALUE_ANTIALIAS_ON);
  g.drawImage(image, 0, 0, width, height, null);
  g.dispose();
  return resizedImage;
}

代码示例来源:origin: sarxos/webcam-capture

/**
 * A convenience method for getting ARGB pixels from an image. This tries to avoid the
 * performance penalty of BufferedImage.getRGB unmanaging the image.
 *
 * @param image a BufferedImage object
 * @param x the left edge of the pixel block
 * @param y the right edge of the pixel block
 * @param width the width of the pixel array
 * @param height the height of the pixel array
 * @param pixels the array to hold the returned pixels. May be null.
 * @return the pixels
 * @see #setRGB
 */
public int[] getRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
  int type = image.getType();
  if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) {
    return (int[]) image.getRaster().getDataElements(x, y, width, height, pixels);
  }
  return image.getRGB(x, y, width, height, pixels, 0, width);
}

代码示例来源:origin: libgdx/libgdx

splitImage = new BufferedImage(region.width, region.height, page.getType());
BufferedImage paddedImage = new BufferedImage(splitImage.getWidth() + padding * 2, splitImage.getHeight() + padding * 2,
  page.getType());
Graphics2D g2 = paddedImage.createGraphics();
g2.drawImage(splitImage, padding, padding, null);
g2.dispose();
return paddedImage;

代码示例来源:origin: libgdx/libgdx

splitImage = extractImage(img, region, outputDirFile, 0);
if (region.width != region.originalWidth || region.height != region.originalHeight) {
  BufferedImage originalImg = new BufferedImage(region.originalWidth, region.originalHeight, img.getType());
  Graphics2D g2 = originalImg.createGraphics();
  g2.drawImage(splitImage, (int) region.offsetX, (int) (region.originalHeight - region.height - region.offsetY), null);
  g2.dispose();
  splitImage = originalImg;

代码示例来源:origin: sarxos/webcam-capture

/**
   * A convenience method for setting ARGB pixels in an image. This tries to avoid the performance
   * penalty of BufferedImage.setRGB unmanaging the image.
   *
   * @param image a BufferedImage object
   * @param x the left edge of the pixel block
   * @param y the right edge of the pixel block
   * @param width the width of the pixel array
   * @param height the height of the pixel array
   * @param pixels the array of pixels to set
   * @see #getRGB
   */
  public void setRGB(BufferedImage image, int x, int y, int width, int height, int[] pixels) {
    int type = image.getType();
    if (type == BufferedImage.TYPE_INT_ARGB || type == BufferedImage.TYPE_INT_RGB) {
      image.getRaster().setDataElements(x, y, width, height, pixels);
    } else {
      image.setRGB(x, y, width, height, pixels, 0, width);
    }
  }
}

代码示例来源:origin: plantuml/plantuml

/**
 * Extracts image pixels into byte array "pixels"
 */
protected void getImagePixels() {
  int w = image.getWidth();
  int h = image.getHeight();
  int type = image.getType();
  if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR)) {
    // create new image with right size/format
    BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = temp.createGraphics();
    g.drawImage(image, 0, 0, null);
    image = temp;
  }
  pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
}

代码示例来源:origin: libgdx/libgdx

splitImage = extractImage(img, region, outputDirFile, 0);
if (region.width != region.originalWidth || region.height != region.originalHeight) {
  BufferedImage originalImg = new BufferedImage(region.originalWidth, region.originalHeight, img.getType());
  Graphics2D g2 = originalImg.createGraphics();
  g2.drawImage(splitImage, (int) region.offsetX, (int) (region.originalHeight - region.height - region.offsetY), null);
  g2.dispose();
  splitImage = originalImg;

相关文章