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

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

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

BufferedImage.getData介绍

暂无

代码示例

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

/**
   * Return image raster as bytes array.
   *
   * @param bi the {@link BufferedImage}
   * @return The raster data as byte array
   */
  public static byte[] imageToBytes(BufferedImage bi) {
    return ((DataBufferByte) bi.getData().getDataBuffer()).getData();
  }
}

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

public static Image getImageFromArray(int[] pixels, int width, int height) {
     BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
     WritableRaster raster = (WritableRaster) image.getData();
     raster.setPixels(0,0,width,height,pixels);
     return image;
   }

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

DataBufferInt dataIntBuf = (DataBufferInt) img.getData().getDataBuffer();
singleCursor = IntBuffer.wrap(dataIntBuf.getData());
cursors.add(singleCursor);

代码示例来源:origin: twosigma/beakerx

@Test
public void deserialize_resultObjectHasData() throws Exception {
 //given
 ObjectMapper mapper = new ObjectMapper();
 JsonNode actualObj = mapper.readTree(json);
 BufferedImageDeserializer deserializer = new BufferedImageDeserializer(new BasicObjectSerializer());
 //when
 BufferedImage bufferedImage = (BufferedImage) deserializer.deserialize(actualObj, mapper);
 //then
 Assertions.assertThat(bufferedImage).isNotNull();
 Assertions.assertThat(bufferedImage.getData()).isNotNull();
}

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

@Override
public Raster readRaster(int imageIndex, ImageReadParam param) throws IOException {
  return read(imageIndex, param).getData();
}

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

private static MagickImage rgbToMagic(BufferedImage pImage, boolean pAlpha) throws MagickException {
  MagickImage image = new MagickImage();
  BufferedImage buffered = ImageUtil.toBuffered(pImage, pAlpha ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
  // Need to get data of sub raster, not the full data array, this is
  // just a convenient way
  Raster raster;
  if (buffered.getRaster().getParent() != null) {
    raster = buffered.getData(new Rectangle(buffered.getWidth(), buffered.getHeight()));
  }
  else {
    raster = buffered.getRaster();
  }
  image.constituteImage(buffered.getWidth(), buffered.getHeight(), pAlpha ? "ABGR" : "BGR",
             ((DataBufferByte) raster.getDataBuffer()).getData());
  return image;
}

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

@Override
public Raster computeTile(int tileX, int tileY) {
  int posx = tileX * tileWidth + tileGridXOffset;
  int posy = tileY * tileHeight + tileGridYOffset;
  ImageInTile candidate =
      sources.stream()
          .filter(it -> it.posx == posx && it.posy == posy)
          .findFirst()
          .orElse(null);
  if (candidate != null) {
    return candidate.image.getData().createTranslatedChild(posx, posy);
  }
  // not inside the available grid, build a white cell then
  WritableRaster dest =
      createWritableRaster(
          sampleModel, new Point(tileXToX(tileX), tileYToY(tileY)));
  BufferedImage bi = new BufferedImage(getColorModel(), dest, false, null);
  Graphics2D g2D = (Graphics2D) bi.getGraphics();
  g2D.setColor(Color.WHITE);
  g2D.fillRect(0, 0, bi.getWidth(), bi.getHeight());
  g2D.dispose();
  return dest;
}

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

raster = buffered.getData(new Rectangle(buffered.getWidth(), buffered.getHeight()));

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

Raster data = bi.getData();
StringBuilder sb = new StringBuilder();
for (int y = 0; y < data.getHeight(); y += (y == 4 && y < data.getHeight() / 2 ? data.getHeight() - 8 : 1)) {

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

DataBuffer dBuf = image.getData().getDataBuffer();
if (dBuf.getDataType() == DataBuffer.TYPE_BYTE)

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

@Test
public void testApplyOrientation() throws IOException {
  InputStream inputStream = getClassLoaderResource("/contrib/tiff/multipage.tif").openStream();
  File inputFile = File.createTempFile("imageiotest", "tif");
  byte[] data = FileUtil.read(inputStream);
  FileUtil.write(inputFile, data);
  inputStream.close();
  BufferedImage image = ImageIO.read(inputFile);
  // rotate by 90�
  BufferedImage image90 = TIFFUtilities.applyOrientation(image, TIFFExtension.ORIENTATION_RIGHTTOP);
  // rotate by 270�
  BufferedImage image360 = TIFFUtilities.applyOrientation(image90, TIFFExtension.ORIENTATION_LEFTBOT);
  byte[] original = ((DataBufferByte) image.getData().getDataBuffer()).getData();
  byte[] rotated = ((DataBufferByte) image360.getData().getDataBuffer()).getData();
  Assert.assertArrayEquals(original, rotated);
}

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

int type = sourceImage.getType();
if (type == BufferedImage.TYPE_INT_RGB || type == BufferedImage.TYPE_INT_ARGB) {
  int[] pixels = (int[]) sourceImage.getData().getDataElements(0, 0, width, height, null);
  for (int i = 0; i < picsize; i++) {
    int p = pixels[i];
  byte[] pixels = (byte[]) sourceImage.getData().getDataElements(0, 0, width, height, null);
  for (int i = 0; i < picsize; i++) {
    data[i] = (pixels[i] & 0xff);
  short[] pixels = (short[]) sourceImage.getData().getDataElements(0, 0, width, height, null);
  for (int i = 0; i < picsize; i++) {
    data[i] = (pixels[i] & 0xffff) / 256;
  byte[] pixels = (byte[]) sourceImage.getData().getDataElements(0, 0, width, height, null);
  int offset = 0;
  for (int i = 0; i < picsize; i++) {

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

int posy = (int) (topTile - tile.getTileRow()) * DEFAULT_TILE_SIZE;
image.getRaster().setRect(posx, posy, tileImage.getData());

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

img.getData().getPixel(100, 100, pixel);
assertEquals(255, pixel[0]);
assertEquals(0, pixel[1]);

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

private double similarityMeasure(BufferedImage leftRegion, BufferedImage rightRegion) {
  double ssd = 0;
  Raster left = leftRegion.getData();
  Raster right = rightRegion.getData();

  for(int x = 0; x < leftRegion.getWidth();  x++) {
    for(int y = 0; y < leftRegion.getHeight(); y++) {
      double diff = left.getSampleDouble(x,y,0) - right.getSampleDouble(x,y,0);
      ssd += diff*diff;
    }
  }
  return 1/ssd;
}

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

BufferedImage img = ImageIO.read(new File(filename)); // Throws IOException
int[] pixels = img.getRGB(0,0, img.getWidth(), img.getHeight, null, 0, img.getWidth());

// also available through the BufferedImage's Raster, in multiple formats.
Raster r = img.getData();
int[] pixels = r.getPixels(0,0,r.getWidth(), r.getHeight(), (int[])null);

代码示例来源:origin: net.java.dev.jai-imageio/jai-imageio-core-standalone

public Raster readRaster(int imageIndex,
             ImageReadParam param) throws IOException {
  BufferedImage bi = read(imageIndex, param);
  return bi.getData();
}

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

bi.getData().getPixel(i, 99 - i, pixel);
assertEquals(0, pixel[0]);
assertEquals(0, pixel[1]);

代码示例来源: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: dcm4che/dcm4che

static int sizeOf(BufferedImage bi) {
  DataBuffer db = bi.getData().getDataBuffer();
  return db.getSize() * db.getNumBanks()
      * (DataBuffer.getDataTypeSize(db.getDataType()) >>> 3);
}

相关文章