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

x33g5p2x  于2022-01-28 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(141)

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

Raster.createPackedRaster介绍

暂无

代码示例

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

WritableRaster raster = Raster.createPackedRaster(imageBuffer, width, height, width, masks, null);
BufferedImage view = new BufferedImage(colorModel, raster, false, null);

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

cm = new DirectColorModel(16, 0x7C00, 0x3E0, 0x1F);
  buffer = new DataBufferUShort(strideElementsAligned * height);
  raster = Raster.createPackedRaster(buffer, bih.biWidth, height, strideElementsAligned, ((DirectColorModel) cm).getMasks(), null);
  break;
case 32:
  cm = new DirectColorModel(32, 0xFF0000, 0xFF00, 0xFF);
  buffer = new DataBufferInt(strideElementsAligned * height);
  raster = Raster.createPackedRaster(buffer, bih.biWidth, height, strideElementsAligned, ((DirectColorModel) cm).getMasks(), null);
  break;
default:

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

private static Paint create8x8Pattern(final byte[] pPattern) {
  WritableRaster raster = Raster.createPackedRaster(new DataBufferByte(pPattern, 8), 8, 8, 1, new Point());
  BufferedImage img = new BufferedImage(QuickDraw.MONOCHROME, raster, false, null);
  return new TexturePaint(img, new Rectangle(8, 8));
}

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

private static Paint create8x8Pattern(final byte[] pPattern, Color fg, Color bg) {
  switch (isSolid(pPattern)) {
    case 0: // 0x00
      return bg;
    case -1: // 0xff
      return fg;
    default:
      // Fall through
  }
  WritableRaster raster = Raster.createPackedRaster(new DataBufferByte(pPattern, 8), 8, 8, 1, new Point());
  IndexColorModel cm = new IndexColorModel(1, 2, new int[] {bg.getRGB(), fg.getRGB()}, 0, false, -1, DataBuffer.TYPE_BYTE);
  BufferedImage img = new BufferedImage(cm, raster, false, null);
  return new TexturePaint(img, new Rectangle(8, 8));
}

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

private BufferedImage readIndexed() {
  // 1 byte: xThumb
  // 1 byte: yThumb
  // 768 bytes: palette
  // x * y bytes: 8 bit indexed pixels
  int w = segment.thumbnail[0] & 0xff;
  int h = segment.thumbnail[1] & 0xff;
  int[] rgbs = new int[256];
  for (int i = 0; i < rgbs.length; i++) {
    rgbs[i] = (segment.thumbnail[3 * i + 2] & 0xff) << 16
        | (segment.thumbnail[3 * i + 3] & 0xff) << 8
        | (segment.thumbnail[3 * i + 4] & 0xff);
  }
  IndexColorModel icm = new InverseColorMapIndexColorModel(8, rgbs.length, rgbs, 0, false, -1, DataBuffer.TYPE_BYTE);
  DataBufferByte buffer = new DataBufferByte(segment.thumbnail, segment.thumbnail.length - 770, 770);
  WritableRaster raster = Raster.createPackedRaster(buffer, w, h, 8, null);
  return new BufferedImage(icm, raster, icm.isAlphaPremultiplied(), null);
}

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

WritableRaster raster = Raster.createPackedRaster(db, (rowBytes * 8) / cmpSize, srcRect.height, cmpSize, null);
BufferedImage image = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);

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

cm = colorModel;
DataBuffer db = new DataBufferByte(dstBytes, dstBytes.length);
raster = Raster.createPackedRaster(db, srcRect.width, srcRect.height, 1, null);
raster = Raster.createPackedRaster(db, srcRect.width, srcRect.height, srcRect.width, ((DirectColorModel) cm).getMasks(), null);
raster = Raster.createPackedRaster(db, srcRect.width, srcRect.height, srcRect.width, ((DirectColorModel) cm).getMasks(), null);

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

WritableRaster raster = Raster.createPackedRaster(db, (rowBytes * 8) / cmpSize, srcRect.height, cmpSize, null);
BufferedImage img = new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);

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

raster = Raster.createPackedRaster(buffer, pWidth, pHeight, pColorModel.getPixelSize(), LOCATION_UPPER_LEFT);
raster = Raster.createPackedRaster(buffer, pWidth, pHeight, pWidth, pcm.getMasks(), LOCATION_UPPER_LEFT);

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

WritableRaster raster = Raster.createPackedRaster(buffer, width, height, resource.depth(), null);
  WritableRaster mask = Raster.createPackedRaster(maskBuffer, width, height, resource.depth(), null);
WritableRaster raster = Raster.createPackedRaster(buffer, width, height, resource.depth(), null);

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

private void readBitmap32(final BitmapDescriptor pBitmap) throws IOException {
  int[] pixels = new int[pBitmap.getWidth() * pBitmap.getHeight()];
  // Will create TYPE_INT_ARGB
  DirectColorModel cm = (DirectColorModel) ColorModel.getRGBdefault();
  DataBuffer buffer = new DataBufferInt(pixels, pixels.length);
  WritableRaster raster = Raster.createPackedRaster(
      buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null
  );
  pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
  for (int y = 0; y < pBitmap.getHeight(); y++) {
    int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth();
    imageInput.readFully(pixels, offset, pBitmap.getWidth());
    if (abortRequested()) {
      processReadAborted();
      break;
    }            
    processImageProgress(100 * y / (float) pBitmap.getHeight());
  }
  // There might be a mask here as well, but we'll ignore it,
  // and use the 8 bit alpha channel in the ARGB pixel data
}

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

private void readBitmap16(final BitmapDescriptor pBitmap) throws IOException {
  // TODO: No idea if this actually works..
  short[] pixels = new short[pBitmap.getWidth() * pBitmap.getHeight()];
  // TODO: Support TYPE_USHORT_565 and the RGB 444/ARGB 4444 layouts
  // Will create TYPE_USHORT_555
  DirectColorModel cm = new DirectColorModel(16, 0x7C00, 0x03E0, 0x001F);
  DataBuffer buffer = new DataBufferShort(pixels, pixels.length);
  WritableRaster raster = Raster.createPackedRaster(
      buffer, pBitmap.getWidth(), pBitmap.getHeight(), pBitmap.getWidth(), cm.getMasks(), null
  );
  pBitmap.image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
  for (int y = 0; y < pBitmap.getHeight(); y++) {
    int offset = (pBitmap.getHeight() - y - 1) * pBitmap.getWidth();
    imageInput.readFully(pixels, offset, pBitmap.getWidth());
    // Skip to 32 bit boundary
    if (pBitmap.getWidth() % 2 != 0) {
      imageInput.readShort();
    }
    if (abortRequested()) {
      processReadAborted();
      break;
    }
    processImageProgress(100 * y / (float) pBitmap.getHeight());
  }
  // TODO: Might be mask!?
}

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

case 2:
case 4:
  rowRaster = Raster.createPackedRaster(new DataBufferByte(rowSizeBytes), width, 1, header.getBitCount(), null);
  break;
case 8:

代码示例来源:origin: com.twelvemonkeys.imageio/imageio-pict

private static Paint create8x8Pattern(final byte[] pPattern) {
  WritableRaster raster = Raster.createPackedRaster(new DataBufferByte(pPattern, 8), 8, 8, 1, new Point());
  BufferedImage img = new BufferedImage(QuickDraw.MONOCHROME, raster, false, null);
  return new TexturePaint(img, new Rectangle(8, 8));
}

代码示例来源:origin: com.twelvemonkeys.imageio/twelvemonkeys-imageio-pict

private static TexturePaint create8x8Pattern(final byte[] pPattern) {
    WritableRaster raster = Raster.createPackedRaster(new DataBufferByte(pPattern, 8), 8, 8, 1, new Point());
    BufferedImage img = new BufferedImage(QuickDraw.MONOCHROME, raster, false, null);
    return new TexturePaint(img, new Rectangle(8, 8));
  }
}

代码示例来源:origin: sjamesr/jfreesane

private BufferedImage decodeSingleBitGrayscaleImage(DataBuffer buffer) {
 WritableRaster raster = Raster.createPackedRaster(buffer, width, height, 1, new Point(0, 0));
 return new BufferedImage(
   new IndexColorModel(
     1,
     2,
     new byte[] {(byte) 0xff, 0},
     new byte[] {(byte) 0xff, 0},
     new byte[] {(byte) 0xff, 0}),
   raster,
   false,
   null);
}

代码示例来源:origin: com.twelvemonkeys.imageio/imageio-pict

private static Paint create8x8Pattern(final byte[] pPattern, Color fg, Color bg) {
  switch (isSolid(pPattern)) {
    case 0: // 0x00
      return bg;
    case -1: // 0xff
      return fg;
    default:
      // Fall through
  }
  WritableRaster raster = Raster.createPackedRaster(new DataBufferByte(pPattern, 8), 8, 8, 1, new Point());
  IndexColorModel cm = new IndexColorModel(1, 2, new int[] {bg.getRGB(), fg.getRGB()}, 0, false, -1, DataBuffer.TYPE_BYTE);
  BufferedImage img = new BufferedImage(cm, raster, false, null);
  return new TexturePaint(img, new Rectangle(8, 8));
}

代码示例来源:origin: org.icepdf.os/icepdf-core

public BufferedImage getBufferedImage() {
  byte[] bytes = getData(true);
  if (bytes == null)
    return null;
  // make a a DEEP copy so we can't alter
  int len = bytes.length;
  byte[] copy = new byte[len];
  System.arraycopy(bytes, 0, copy, 0, len);
  /** create an image from the raw data */
  DataBuffer db = new DataBufferByte(copy, copy.length);
  WritableRaster raster = Raster.createPackedRaster(db, width, height, 1, null);
  BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
  image.setData(raster);
  return image;
}

代码示例来源:origin: com.github.mike10004/commons-imaging

private BufferedImage readImage(final WbmpHeader wbmpHeader, final InputStream is)
    throws IOException {
  final int rowLength = (wbmpHeader.width + 7) / 8;
  final byte[] image = readBytes("Pixels", is,
      rowLength * wbmpHeader.height, "Error reading image pixels");
  final DataBufferByte dataBuffer = new DataBufferByte(image, image.length);
  final WritableRaster raster = Raster.createPackedRaster(dataBuffer,
      wbmpHeader.width, wbmpHeader.height, 1, null);
  final int[] palette = { 0x000000, 0xffffff };
  final IndexColorModel colorModel = new IndexColorModel(1, 2, palette, 0,
      false, -1, DataBuffer.TYPE_BYTE);
  return new BufferedImage(colorModel, raster,
      colorModel.isAlphaPremultiplied(), new Properties());
}

代码示例来源:origin: com.twelvemonkeys.imageio/imageio-jpeg

private BufferedImage readIndexed() {
  // 1 byte: xThumb
  // 1 byte: yThumb
  // 768 bytes: palette
  // x * y bytes: 8 bit indexed pixels
  int w = segment.thumbnail[0] & 0xff;
  int h = segment.thumbnail[1] & 0xff;
  int[] rgbs = new int[256];
  for (int i = 0; i < rgbs.length; i++) {
    rgbs[i] = (segment.thumbnail[3 * i + 2] & 0xff) << 16
        | (segment.thumbnail[3 * i + 3] & 0xff) << 8
        | (segment.thumbnail[3 * i + 4] & 0xff);
  }
  IndexColorModel icm = new InverseColorMapIndexColorModel(8, rgbs.length, rgbs, 0, false, -1, DataBuffer.TYPE_BYTE);
  DataBufferByte buffer = new DataBufferByte(segment.thumbnail, segment.thumbnail.length - 770, 770);
  WritableRaster raster = Raster.createPackedRaster(buffer, w, h, 8, null);
  return new BufferedImage(icm, raster, icm.isAlphaPremultiplied(), null);
}

相关文章