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

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

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

BufferedImage.setData介绍

暂无

代码示例

代码示例来源:origin: org.apache.poi/poi

public void drawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform)
{
  BufferedImage bufferedimage = new BufferedImage(renderedimage.getColorModel(), renderedimage.getData().createCompatibleWritableRaster(), false, null);
  bufferedimage.setData(renderedimage.getData());
  drawImage(bufferedimage, affinetransform, null);
}

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

private IndexColorModel createIndexColorModel(Raster pSource) {
  BufferedImage image = new BufferedImage(pSource.getWidth(), pSource.getHeight(),
                      BufferedImage.TYPE_INT_ARGB);
  image.setData(pSource);
  return IndexImage.getIndexColorModel(image, 256, IndexImage.TRANSPARENCY_BITMASK);
}

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

private IndexColorModel createIndexColorModel(Raster pSource) {
  BufferedImage image = new BufferedImage(pSource.getWidth(), pSource.getHeight(), BufferedImage.TYPE_INT_ARGB);
  image.setData(pSource);
  return IndexImage.getIndexColorModel(image, 256, IndexImage.TRANSPARENCY_BITMASK | IndexImage.COLOR_SELECTION_QUALITY);
}

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

public void processFrame(byte[] frame, int width, int height)
{
  DataBuffer videoBuffer = new DataBufferByte(frame,frame.length);
  BufferedImage currentImage = new BufferedImage(width,height,BufferedImage.TYPE_3BYTE_BGR);
  ComponentSampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_BYTE,width,height,3,width*3,new int[] {2,1,0});
  Raster raster = Raster.createRaster(sampleModel,videoBuffer,null);
  currentImage.setData(raster);
}

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

private static BufferedImage getAlphaImage(BufferedImage image) throws IOException
{
  if (!image.getColorModel().hasAlpha())
  {
    return null;
  }
  if (image.getTransparency() == Transparency.BITMASK)
  {
    throw new UnsupportedOperationException("BITMASK Transparency JPEG compression is not" +
        " useful, use LosslessImageFactory instead");
  }
  WritableRaster alphaRaster = image.getAlphaRaster();
  if (alphaRaster == null)
  {
    // happens sometimes (PDFBOX-2654) despite colormodel claiming to have alpha
    return null;
  }
  BufferedImage alphaImage = new BufferedImage(image.getWidth(), image.getHeight(),
      BufferedImage.TYPE_BYTE_GRAY);
  alphaImage.setData(alphaRaster);
  return alphaImage;
}

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

@Override
  public BufferedImage toRGBImage(WritableRaster raster) throws IOException
  {
    init();

    //
    // WARNING: this method is performance sensitive, modify with care!
    //
    // Please read PDFBOX-3854 and PDFBOX-2092 and look at the related commits first.
    // The current code returns TYPE_INT_RGB images which prevents slowness due to threads
    // blocking each other when TYPE_CUSTOM images are used.
    BufferedImage image = new BufferedImage(raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_RGB);
    image.setData(raster);
    return image;
  }
}

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

if (COSName.ALPHA.equals(softMask.getSubType()))
  gray.setData(image.getAlphaRaster());

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

image.setData(raster);
    temp.setData(mask);
    graphics.setComposite(AlphaComposite.DstIn);
    graphics.drawImage(temp, 0, 0, null);
  image.setData(raster);
image.setData(raster);

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

byte[] raw = new byte[width*height*3];
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
file.read(frame);
DataBuffer buffer = new DataBufferByte(frame, frame.length);
//The most difficult part of awt api for me to learn
SampleModel sampleModel = new ComponentSampleModel(DataBuffer.TYPE_BYTE, width, height, 3, width*3, new int[]{2,1,0});
Raster raster = Raster.createRaster(sampleModel, buffer, null);
image.setData(raster);

代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.common/common-image

private IndexColorModel createIndexColorModel(Raster pSource) {
  BufferedImage image = new BufferedImage(pSource.getWidth(), pSource.getHeight(), BufferedImage.TYPE_INT_ARGB);
  image.setData(pSource);
  return IndexImage.getIndexColorModel(image, 256, IndexImage.TRANSPARENCY_BITMASK | IndexImage.COLOR_SELECTION_QUALITY);
}

代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.common/common-image

private IndexColorModel createIndexColorModel(Raster pSource) {
  BufferedImage image = new BufferedImage(pSource.getWidth(), pSource.getHeight(),
                      BufferedImage.TYPE_INT_ARGB);
  image.setData(pSource);
  return IndexImage.getIndexColorModel(image, 256, IndexImage.TRANSPARENCY_BITMASK);
}

代码示例来源: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: 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: us.ihmc/IHMCROSTools

public static BufferedImage bufferedImageFromByteArrayJpeg(ColorModel colorModel, byte[] payload, int width, int height)
{
 BufferedImage ret = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
 DataBuffer dataBuffer = new DataBufferByte(payload, payload.length, 0);
 SampleModel sampleModel = colorModel.createCompatibleSampleModel(width, height);
 WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer, null);
 ret.setData(raster);
 return ret;
}

代码示例来源:origin: us.ihmc/ihmc-ros-tools

public static BufferedImage bufferedImageFromByteArrayJpeg(ColorModel colorModel, byte[] payload, int width, int height)
{
 BufferedImage ret = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
 DataBuffer dataBuffer = new DataBufferByte(payload, payload.length, 0);
 SampleModel sampleModel = colorModel.createCompatibleSampleModel(width, height);
 WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer, null);
 ret.setData(raster);
 return ret;
}

代码示例来源:origin: net.imagej/ij

/** Returns a copy of this image as a TYPE_USHORT_GRAY BufferedImage. */
public BufferedImage get16BitBufferedImage() {
  BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_GRAY);
  Raster raster = bi.getData();
  DataBufferUShort db = (DataBufferUShort)raster.getDataBuffer();
  System.arraycopy(getPixels(), 0, db.getData(), 0, db.getData().length);
  bi.setData(raster);
  return bi;
}

代码示例来源:origin: com.haulmont.thirdparty/poi

public void drawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform)
{
  BufferedImage bufferedimage = new BufferedImage(renderedimage.getColorModel(), renderedimage.getData().createCompatibleWritableRaster(), false, null);
  bufferedimage.setData(renderedimage.getData());
  drawImage(bufferedimage, affinetransform, null);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

public void drawRenderedImage(RenderedImage renderedimage, AffineTransform affinetransform)
{
  BufferedImage bufferedimage = new BufferedImage(renderedimage.getColorModel(), renderedimage.getData().createCompatibleWritableRaster(), false, null);
  bufferedimage.setData(renderedimage.getData());
  drawImage(bufferedimage, affinetransform, null);
}

代码示例来源:origin: com.harium.etyl/etyl

public void createBuffer(byte[] imageData) {
  DataBufferByte dataBuffer = new DataBufferByte(imageData, imageData.length);
  originalBuffer.setData(Raster.createRaster(originalBuffer.getSampleModel(), dataBuffer, null));
  resetImage();
}

代码示例来源:origin: us.ihmc/ihmc-ros-tools

public static BufferedImage bufferedImageFromRosMessageRaw(ColorModel colorModel, sensor_msgs.Image imageMessage)
{
 int width = imageMessage.getWidth();
 int height = imageMessage.getHeight();
 byte[] payload = imageMessage.getData().array();
 BufferedImage ret = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
 DataBuffer dataBuffer = new DataBufferByte(payload, payload.length, imageMessage.getData().arrayOffset());
 SampleModel sampleModel = colorModel.createCompatibleSampleModel(width, height);
 WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer, null);
 ret.setData(raster);
 return ret;
}

相关文章