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

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

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

BufferedImage.getColorModel介绍

[英]Returns the ColorModel.
[中]返回ColorModel

代码示例

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

public Rect (BufferedImage source, int left, int top, int newWidth, int newHeight, boolean isPatch) {
  image = new BufferedImage(source.getColorModel(),
    source.getRaster().createWritableChild(left, top, newWidth, newHeight, 0, 0, null),
    source.getColorModel().isAlphaPremultiplied(), null);
  offsetX = left;
  offsetY = top;
  regionWidth = newWidth;
  regionHeight = newHeight;
  originalWidth = source.getWidth();
  originalHeight = source.getHeight();
  width = newWidth;
  height = newHeight;
  this.isPatch = isPatch;
}

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

public static BufferedImage transformImage(BufferedImage image, AffineTransform transform) throws Exception {

  AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC);

  BufferedImage destinationImage = op.createCompatibleDestImage(image, (image.getType() == BufferedImage.TYPE_BYTE_GRAY) ? image.getColorModel() : null );
  Graphics2D g = destinationImage.createGraphics();
  g.setBackground(Color.WHITE);
  g.clearRect(0, 0, destinationImage.getWidth(), destinationImage.getHeight());
  destinationImage = op.filter(image, destinationImage);
  return destinationImage;
}

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

private static BufferedImage deepCopy(BufferedImage bi) {
    final ColorModel cm = bi.getColorModel();
    final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
    final WritableRaster raster = bi.copyData(bi.getRaster().createCompatibleWritableRaster());
    return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
  }
}

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

public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM, int width, int height) {
  BufferedImage image;
  if (destCM == null) {
    destCM = src.getColorModel();
    // Not much support for ICM
    if (destCM instanceof IndexColorModel) {
      destCM = ColorModel.getRGBdefault();
    }
  }
  image = new BufferedImage (destCM,
                destCM.createCompatibleWritableRaster(width, height),
                destCM.isAlphaPremultiplied(), null);
  return image;
}

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

ColorModel srcCM = src.getColorModel();
ColorModel dstCM;
BufferedImage origDst = dst;
  src = icm.convertToIntDiscrete(src.getRaster(), false);
  srcCM = src.getColorModel();
  dstCM = dst.getColorModel();
  if (srcCM.getColorSpace().getType() !=
    dstCM.getColorSpace().getType())
    dstCM = dst.getColorModel();
    dstCM = dst.getColorModel();

代码示例来源:origin: MovingBlocks/Terasology

@Override
public void render(BufferedImage img, Region region) {
  FloraFacet treeFacet = region.getFacet(FloraFacet.class);
  Graphics2D g = img.createGraphics();
  int width = img.getWidth();
  ColorModel colorModel = img.getColorModel();
  ColorBlender blender = ColorBlenders.forColorModel(ColorModels.RGBA, colorModel);
  DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer();
  for (Entry<BaseVector3i, FloraType> entry : treeFacet.getRelativeEntries().entrySet()) {
    FloraType treeGen = entry.getValue();
    int wx = entry.getKey().getX();
    int wz = entry.getKey().getZ();
    Color color = colorFunc.apply(treeGen);
    int src = color.rgba();
    int dst = dataBuffer.getElem(wz * width + wx);
    int mix = blender.blend(src, dst);
    dataBuffer.setElem(wz * width + wx, mix);
  }
  g.dispose();
}

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

public Rect (BufferedImage source, int left, int top, int newWidth, int newHeight, boolean isPatch) {
  image = new BufferedImage(source.getColorModel(),
    source.getRaster().createWritableChild(left, top, newWidth, newHeight, 0, 0, null),
    source.getColorModel().isAlphaPremultiplied(), null);
  offsetX = left;
  offsetY = top;
  regionWidth = newWidth;
  regionHeight = newHeight;
  originalWidth = source.getWidth();
  originalHeight = source.getHeight();
  width = newWidth;
  height = newHeight;
  this.isPatch = isPatch;
}

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

private BufferedImage toCompatibleImage(BufferedImage image)
{
  // obtain the current system graphical settings
  GraphicsConfiguration gfx_config = GraphicsEnvironment.
    getLocalGraphicsEnvironment().getDefaultScreenDevice().
    getDefaultConfiguration();

  /*
   * if image is already compatible and optimized for current system 
   * settings, simply return it
   */
  if (image.getColorModel().equals(gfx_config.getColorModel()))
    return image;

  // image is not optimized, so create a new image that is
  BufferedImage new_image = gfx_config.createCompatibleImage(
      image.getWidth(), image.getHeight(), image.getTransparency());

  // get the graphics context of the new image to draw the old image on
  Graphics2D g2d = (Graphics2D) new_image.getGraphics();

  // actually draw the image and dispose of context no longer needed
  g2d.drawImage(image, 0, 0, null);
  g2d.dispose();

  // return the new optimized image
  return new_image; 
}

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

type = BufferedImage.TYPE_INT_ARGB;
bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
return bimage.getColorModel().hasAlpha();

代码示例来源:origin: kevin-wayne/algs4

WritableRaster raster = offscreenImage.getRaster();
WritableRaster newRaster;
newRaster = raster.createWritableChild(0, 0, width, height, 0, 0, new int[] {0, 1, 2});
DirectColorModel cm = (DirectColorModel) offscreenImage.getColorModel();
DirectColorModel newCM = new DirectColorModel(cm.getPixelSize(),
                       cm.getRedMask(),
                       cm.getGreenMask(),
                       cm.getBlueMask());
BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false,  null);
try {
  ImageIO.write(rgbBuffer, suffix, file);

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

ICC_ColorSpace cmykCS = new ICC_ColorSpace(cmykProfile);
BufferedImage rgbImage = new BufferedImage(cmykRaster.getWidth(), cmykRaster.getHeight(), BufferedImage.TYPE_INT_RGB);
WritableRaster rgbRaster = rgbImage.getRaster();
ColorSpace rgbCS = rgbImage.getColorModel().getColorSpace();
ColorConvertOp cmykToRgb = new ColorConvertOp(cmykCS, rgbCS, null);
cmykToRgb.filter(cmykRaster, rgbRaster);

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

@Override
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM) {
  if (dstCM == null)
    dstCM = src.getColorModel();
  return new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), dstCM.isAlphaPremultiplied(), null);
}

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

private void extractAndSetBackgroundColor(final BufferedImage pImage) {
  // TODO: bgColor request attribute instead of parameter?
  if (pImage.getColorModel().hasAlpha()) {
    String bgColor = originalRequest.getParameter("bg.color");
    if (bgColor != null) {
      Color color = StringUtil.toColor(bgColor);
      Graphics2D g = pImage.createGraphics();
      try {
        g.setColor(color);
        g.setComposite(AlphaComposite.DstOver);
        g.fillRect(0, 0, pImage.getWidth(), pImage.getHeight());
      }
      finally {
        g.dispose();
      }
    }
  }
}

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

public final BufferedImage createCompatibleDestImage(final BufferedImage pInput, final ColorModel pModel) {
  if (pInput == null) {
    throw new NullPointerException("pInput == null");
  }
  ColorModel cm = pModel != null ? pModel : pInput.getColorModel();
  // TODO: Might not work with all colormodels..
  // If indexcolormodel, we probably don't want to use that...
  // NOTE: Either BOTH or NONE of the images must have ALPHA
  return new BufferedImage(cm, ImageUtil.createCompatibleWritableRaster(pInput, cm, width, height),
               cm.isAlphaPremultiplied(), null);
}

代码示例来源:origin: kevin-wayne/algs4

WritableRaster raster = onscreenImage.getRaster();
WritableRaster newRaster;
newRaster = raster.createWritableChild(0, 0, width, height, 0, 0, new int[] {0, 1, 2});
DirectColorModel cm = (DirectColorModel) onscreenImage.getColorModel();
DirectColorModel newCM = new DirectColorModel(cm.getPixelSize(),
                       cm.getRedMask(),
                       cm.getGreenMask(),
                       cm.getBlueMask());
BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false,  null);
try {
  ImageIO.write(rgbBuffer, suffix, file);

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

WritableRaster rgbRaster = rgbImage.getRaster();
ColorSpace rgbCS = rgbImage.getColorModel().getColorSpace();
ColorConvertOp cmykToRgb = new ColorConvertOp(cmykCS, rgbCS, null);
cmykToRgb.filter(cmykRaster, rgbRaster);

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

@Override
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dstCM) {
  if (dstCM == null) {
    dstCM = src.getColorModel();
  }
  return new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), dstCM.isAlphaPremultiplied(), null);
}

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

@Test
public void testReadClipped() throws IOException {
  BufferedImage image = Paths.readClipped(resourceAsIIOStream("/jpeg/grape_with_path.jpg"));
  assertNotNull(image);
  // Same dimensions as original
  assertEquals(857, image.getWidth());
  assertEquals(1800, image.getHeight());
  // Transparent
  assertTrue(image.getColorModel().getTransparency() == Transparency.TRANSLUCENT);
  // Corners (at least) should be transparent
  assertEquals(0, image.getRGB(0, 0));
  assertEquals(0, image.getRGB(image.getWidth() - 1, 0));
  assertEquals(0, image.getRGB(0, image.getHeight() - 1));
  assertEquals(0, image.getRGB(image.getWidth() - 1, image.getHeight() - 1));
  // Center opaque
  assertEquals(0xff, image.getRGB(image.getWidth() / 2, image.getHeight() / 2) >>> 24);
  // TODO: Mor sophisticated test that tests all pixels outside path...
}

代码示例来源:origin: magefree/mage

public static BufferedImage deepCopy(BufferedImage bi) {
  ColorModel cm = bi.getColorModel();
  boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
  WritableRaster raster = bi.copyData(null);
  return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}

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

@Test
public void testHandHotspotExplicitDestination() throws IOException {
  CURImageReader reader = createReader();
  reader.setInput(getTestData().get(0).getInputStream());
  BufferedImage image = reader.read(0);
  // Create dest image with same data, except properties...
  BufferedImage dest = new BufferedImage(
      image.getColorModel(), image.getRaster(), image.getColorModel().isAlphaPremultiplied(), null
  );
  ImageReadParam param = new ImageReadParam();
  param.setDestination(dest);
  assertHotSpot(getTestData().get(0), param, new Point(15, 15));
}

相关文章