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

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

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

BufferedImage.getSampleModel介绍

暂无

代码示例

代码示例来源:origin: dermotte/LIRE

/**
 * Check if the image is fail safe for color based features that are actually using 8 bits per pixel RGB.
 *
 * @param bufferedImage
 * @return
 */
public static BufferedImage get8BitRGBImage(BufferedImage bufferedImage) {
  // check if it's (i) RGB and (ii) 8 bits per pixel.
  if (bufferedImage.getType() != BufferedImage.TYPE_INT_RGB || bufferedImage.getSampleModel().getSampleSize(0) != 8) {
    BufferedImage img = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
    img.getGraphics().drawImage(bufferedImage, 0, 0, null);
    bufferedImage = img;
  }
  return bufferedImage;
}

代码示例来源:origin: dermotte/LIRE

/**
 * Check if the image is fail safe for color based features that are actually using 8 bits per pixel RGB.
 *
 * @param bufferedImage
 * @return
 */
public static BufferedImage get8BitRGBImage(BufferedImage bufferedImage) {
  // check if it's (i) RGB and (ii) 8 bits per pixel.
  if (bufferedImage.getType() != BufferedImage.TYPE_INT_RGB || bufferedImage.getSampleModel().getSampleSize(0) != 8) {
    BufferedImage img = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
    img.getGraphics().drawImage(bufferedImage, 0, 0, null);
    bufferedImage = img;
  }
  return bufferedImage;
}

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

protected BufferedImage getStartImage(BufferedImage copyFrom, int width, int height) {
  Map<String, Object> properties = null;
  if (copyFrom.getPropertyNames() != null) {
    properties = new HashMap<String, Object>();
    for (String name : copyFrom.getPropertyNames()) {
      properties.put(name, copyFrom.getProperty(name));
    }
  }
  SampleModel sm = copyFrom.getSampleModel().createCompatibleSampleModel(width, height);
  WritableRaster raster = Raster.createWritableRaster(sm, null);
  BufferedImage image =
      new BufferedImage(
          copyFrom.getColorModel(),
          raster,
          copyFrom.isAlphaPremultiplied(),
          (Hashtable<?, ?>) properties);
  // white background
  Graphics2D g2D = (Graphics2D) image.getGraphics();
  Color save = g2D.getColor();
  g2D.setColor(Color.WHITE);
  g2D.fillRect(0, 0, image.getWidth(), image.getHeight());
  g2D.setColor(save);
  return image;
}

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

private BufferedImage getStartImage(BufferedImage copyFrom) {
  Dimension dim = getStartDimension();
  Hashtable<String, Object> properties = null;
  if (copyFrom.getPropertyNames() != null) {
    properties = new Hashtable<String, Object>();
    for (String name : copyFrom.getPropertyNames()) {
      properties.put(name, copyFrom.getProperty(name));
    }
  }
  SampleModel sm =
      copyFrom.getSampleModel()
          .createCompatibleSampleModel((int) dim.getWidth(), (int) dim.getHeight());
  WritableRaster raster = Raster.createWritableRaster(sm, null);
  ColorModel colorModel = copyFrom.getColorModel();
  boolean alphaPremultiplied = copyFrom.isAlphaPremultiplied();
  DataBuffer dataBuffer =
      createDataBufferFilledWithNoDataValues(raster, colorModel.getPixelSize());
  raster = Raster.createWritableRaster(sm, dataBuffer, null);
  BufferedImage image = new BufferedImage(colorModel, raster, alphaPremultiplied, properties);
  if (levelInfo.getNoDataValue() == null) {
    Graphics2D g2D = (Graphics2D) image.getGraphics();
    Color save = g2D.getColor();
    g2D.setColor(backgroundColor);
    g2D.fillRect(0, 0, image.getWidth(), image.getHeight());
    g2D.setColor(save);
  }
  return image;
}

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

if (specifier.getSampleModel().getTransferType() == dest.getSampleModel().getTransferType() &&
    specifier.getNumBands() <= dest.getSampleModel().getNumBands()) {
  found = true;
  break;

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

checkReadParamBandSettings(pParam, header.bitplanes / 8, image.getSampleModel().getNumBands());

代码示例来源:origin: apache/pdfbox

if (image.getSampleModel() instanceof MultiPixelPackedSampleModel &&
  image.getColorModel().getPixelSize() == 1 &&
  image.getRaster().getNumBands() == 1 &&

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

checkReadParamBandSettings(param, 4, image.getSampleModel().getNumBands());
checkReadParamBandSettings(param, rawType.getNumBands(), image.getSampleModel().getNumBands());

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

checkReadParamBandSettings(pParam, isConvertToRGB() ? 3 : 1, image.getSampleModel().getNumBands());

代码示例来源:origin: org.apache.xmlgraphics/xmlgraphics-commons

public BufferedImageCachableRed(BufferedImage bi,
                    int xloc, int yloc) {
  super((CachableRed)null, new Rectangle(xloc,  yloc,
                      bi.getWidth(),
                      bi.getHeight()),
     bi.getColorModel(), bi.getSampleModel(), xloc, yloc, null);
  this.bi = bi;
}

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

checkReadParamBandSettings(param, rawType.getNumBands(), image.getSampleModel().getNumBands());

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

int numBands = composedImage.getSampleModel().getNumBands();
GridSampleDimension[] sd = new GridSampleDimension[numBands];
for (int i = 0; i < numBands; i++) {

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

assertEquals(type.getNumBands(), image.getSampleModel().getNumBands());
  assertEquals(type.getBitsPerBand(j), image.getSampleModel().getSampleSize(j));

代码示例来源:origin: com.sksamuel.scrimage/scrimage-core

protected int getResultBufferedImageType(BufferedImage srcImg) {
  return nrChannels == 3 ? BufferedImage.TYPE_3BYTE_BGR :
   (nrChannels == 4 ? BufferedImage.TYPE_4BYTE_ABGR :
    (srcImg.getSampleModel().getDataType() == DataBuffer.TYPE_USHORT ?
     BufferedImage.TYPE_USHORT_GRAY : BufferedImage.TYPE_BYTE_GRAY));
 }
}

代码示例来源:origin: com.wizzardo.tools/tools-image

protected int getResultBufferedImageType(BufferedImage srcImg) {
    return nrChannels == 3 ? BufferedImage.TYPE_3BYTE_BGR :
        (nrChannels == 4 ? BufferedImage.TYPE_4BYTE_ABGR :
            (srcImg.getSampleModel().getDataType() == DataBuffer.TYPE_USHORT ?
                BufferedImage.TYPE_USHORT_GRAY : BufferedImage.TYPE_BYTE_GRAY));
  }
}

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

checkReadParamBandSettings(param, rawType.getNumBands(), destination.getSampleModel().getNumBands());

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

SampleModel resultModel = result.getSampleModel();

代码示例来源:origin: org.apache.xmlgraphics/batik-awt-util

/**
 * Construct an instance of CachableRed around a BufferedImage.
 */
public BufferedImageCachableRed(BufferedImage bi) {
  super((CachableRed)null,
     new Rectangle(bi.getMinX(),  bi.getMinY(),
            bi.getWidth(), bi.getHeight()),
     bi.getColorModel(), bi.getSampleModel(),
     bi.getMinX(), bi.getMinY(), null);
  this.bi = bi;
}

代码示例来源:origin: org.apache.xmlgraphics/xmlgraphics-commons

/**
 * Construct an instance of CachableRed around a BufferedImage.
 */
public BufferedImageCachableRed(BufferedImage bi) {
  super((CachableRed)null,
     new Rectangle(bi.getMinX(),  bi.getMinY(),
            bi.getWidth(), bi.getHeight()),
     bi.getColorModel(), bi.getSampleModel(),
     bi.getMinX(), bi.getMinY(), null);
  this.bi = bi;
}

代码示例来源:origin: fr.avianey.apache-xmlgraphics/batik

public void fixAlpha(BufferedImage bi) {
  if ((!bi.getColorModel().hasAlpha()) ||
    (!bi.isAlphaPremultiplied()))
    // No need to fix alpha if it isn't premultiplied...
    return;
  if (GraphicsUtil.is_INT_PACK_Data(bi.getSampleModel(), true))
    fixAlpha_INT_PACK(bi.getRaster());
  else
    fixAlpha_FALLBACK(bi.getRaster());
}

相关文章