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

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

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

BufferedImage.getAlphaRaster介绍

暂无

代码示例

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

WritableRaster alphaRaster = source.getAlphaRaster();
if (alphaRaster == null || (!settings.stripWhitespaceX && !settings.stripWhitespaceY))
  return new Rect(source, 0, 0, source.getWidth(), source.getHeight(), false);

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

WritableRaster alphaRaster = source.getAlphaRaster();
if (alphaRaster == null || (!settings.stripWhitespaceX && !settings.stripWhitespaceY))
  return new Rect(source, 0, 0, source.getWidth(), source.getHeight(), false);

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

final int width = image.getWidth();
final int height = image.getHeight();
final boolean hasAlphaChannel = image.getAlphaRaster() != null;

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

private BufferedImage createMaskedImage() {
    BufferedImage masked = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR);

    Graphics2D graphics = masked.createGraphics();
    try {
      graphics.drawImage(image, 0, 0, null);
    }
    finally {
      graphics.dispose();
    }

    WritableRaster alphaRaster = masked.getAlphaRaster();

    byte[] trans = {0x0};
    for (int y = 0; y < getHeight(); y++) {
      for (int x = 0; x < getWidth(); x++) {
        if (mask.isTransparent(x, y)) {
          alphaRaster.setDataElements(x, y, trans);
        }
      }
    }

    return masked;
  }
}

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

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

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

image.getAlphaRaster().setRect(mask);
image.getAlphaRaster().setRect(mask);
Arrays.fill(solid, (byte) -1);
WritableRaster mask = Raster.createBandedRaster(new DataBufferByte(solid, solid.length), width, height, width, new int[]{0}, new int[]{0}, null);
image.getAlphaRaster().setRect(mask);

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

BufferedImage image = ImageIO.read(new File(name));

int[] alpha = new int[1]; //containg alpha-value for one pixel.
image.getAlphaRaster().getPixel(x, y, alpha);

System.out.println(alpha[0]); //gives the alpha value for x,y

代码示例来源:origin: org.epics/graphene

private GraphBuffer(BufferedImage image){
  this.image = image;
  width = image.getWidth();
  height = image.getHeight();
  pixels = ((DataBufferByte)this.image.getRaster().getDataBuffer()).getData();
  hasAlphaChannel = image.getAlphaRaster() != null;
  g = image.createGraphics();
}

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

public static BufferedImage applyAlphaMask(BufferedImage src, BufferedImage mask) {
  WritableRaster alpha = mask.getAlphaRaster();
  int[] data = new int[mask.getWidth() * mask.getHeight()];
  alpha.getPixels(0, 0, mask.getWidth(), mask.getHeight(), data);
  if (src.getAlphaRaster() == null) {
    BufferedImage t = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
    t.getGraphics().drawImage(src, 0, 0, null);
    src = t;
  }
  src.getAlphaRaster().setPixels(0, 0, mask.getWidth(), mask.getHeight(), data);
  return src;
}

代码示例来源:origin: wizzardo/tools

public static BufferedImage applyAlphaMask(BufferedImage src, BufferedImage mask) {
  WritableRaster alpha = mask.getAlphaRaster();
  int[] data = new int[mask.getWidth() * mask.getHeight()];
  alpha.getPixels(0, 0, mask.getWidth(), mask.getHeight(), data);
  if (src.getAlphaRaster() == null) {
    BufferedImage t = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
    t.getGraphics().drawImage(src, 0, 0, null);
    src = t;
  }
  src.getAlphaRaster().setPixels(0, 0, mask.getWidth(), mask.getHeight(), data);
  return src;
}

代码示例来源:origin: net.java.dev.jna/jna-platform

protected Raster toRaster(Component c, Icon mask) {
  Raster raster = null;
  if (mask != null) {
    Rectangle bounds = new Rectangle(0, 0, mask.getIconWidth(),
                     mask.getIconHeight());
    BufferedImage clip = new BufferedImage(bounds.width,
                        bounds.height,
                        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = clip.createGraphics();
    g.setComposite(AlphaComposite.Clear);
    g.fillRect(0, 0, bounds.width, bounds.height);
    g.setComposite(AlphaComposite.SrcOver);
    mask.paintIcon(c, g, 0, 0);
    raster = clip.getAlphaRaster();
  }
  return raster;
}

代码示例来源:origin: pvto/konte-art

public void setBackground(BufferedImage image, Color color)
{
  DataBuffer ar = image.getAlphaRaster().getDataBuffer();
  int col = ((int) color.getAlpha() << 24)
      + ((int) color.getRed() << 16)
      + ((int) color.getGreen() << 8)
      + ((int) color.getBlue());
  for (int i = 0; i < width * height; i++)
  {
    ar.setElem(i, col);
  }
}
final private Matrix4 HALF = Matrix4.translation(0.5f, 0f, 0f);

代码示例来源:origin: net.java.dev.jna/platform

protected Raster toRaster(Component c, Icon mask) {
  Raster raster = null;
  if (mask != null) {
    Rectangle bounds = new Rectangle(0, 0, mask.getIconWidth(),
                     mask.getIconHeight());
    BufferedImage clip = new BufferedImage(bounds.width,
                        bounds.height,
                        BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = clip.createGraphics();
    g.setComposite(AlphaComposite.Clear);
    g.fillRect(0, 0, bounds.width, bounds.height);
    g.setComposite(AlphaComposite.SrcOver);
    mask.paintIcon(c, g, 0, 0);
    raster = clip.getAlphaRaster();
  }
  return raster;
}

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

public static BufferedImage applyMask(BufferedImage src, BufferedImage mask) {
  if (src.getAlphaRaster() == null) {
    BufferedImage t = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
    t.getGraphics().drawImage(src, 0, 0, null);
    src = t;
  }
  int w = Math.min(src.getWidth(), mask.getWidth());
  int h = Math.min(src.getHeight(), mask.getHeight());
  int[] data = mask.getRGB(0, 0, w, h, null, 0, w);
  for (int i = 0; i < data.length; i++) {
    data[i] = red(data[i]);
  }
  src.getAlphaRaster().setPixels(0, 0, w, h, data);
  return src;
}

代码示例来源:origin: wizzardo/tools

public static BufferedImage applyMask(BufferedImage src, BufferedImage mask) {
  if (src.getAlphaRaster() == null) {
    BufferedImage t = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
    t.getGraphics().drawImage(src, 0, 0, null);
    src = t;
  }
  int w = Math.min(src.getWidth(), mask.getWidth());
  int h = Math.min(src.getHeight(), mask.getHeight());
  int[] data = mask.getRGB(0, 0, w, h, null, 0, w);
  for (int i = 0; i < data.length; i++) {
    data[i] = red(data[i]);
  }
  src.getAlphaRaster().setPixels(0, 0, w, h, data);
  return src;
}

代码示例来源:origin: com.carrotsearch/smartsprites

/**
 * Returns <code>true</code> if the provided image has any kind of transparent areas
 */
public static boolean hasTransparency(BufferedImage image)
{
  final Raster alphaRaster = image.getAlphaRaster();
  if (image.getTransparency() != Transparency.TRANSLUCENT || alphaRaster == null)
  {
    return false;
  }
  int [] pixels = alphaRaster.getPixels(0, 0, alphaRaster.getWidth(), alphaRaster
    .getHeight(), (int []) null);
  for (int i : pixels)
  {
    if (i != 255)
    {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: eseifert/vectorgraphics2d

public ImageDataStream(BufferedImage image, Interleaving interleaving) {
  this.image = image;
  this.interleaving = interleaving;
  width = image.getWidth();
  height = image.getHeight();
  x = -1;
  y = 0;
  Raster alphaRaster = image.getAlphaRaster();
  if (interleaving == Interleaving.ALPHA_ONLY) {
    raster = alphaRaster;
  } else {
    raster = image.getRaster();
  }
  opaque = alphaRaster == null;
  byteBuffer = new LinkedList<>();
  sampleValues = new int[raster.getNumBands()];
  sampleSizes = raster.getSampleModel().getSampleSize();
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

public BufferedImage getSnapshot() {
    if (snapshot == null) {
      snapshot = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                     .getDefaultConfiguration().createCompatibleImage(getWidth(), getHeight());
      if (log) {
        PropUtils.log(ButtonPanel.class, "Created " + snapshot + " custom editor button backing image");
      }
      if (snapshot.getAlphaRaster() == null) {
        //Alpha not supported, could cause corruption (issue
        //39280) - use a bufferedImage which will support alpha,
        //although less efficient to blit
        snapshot = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
      }
      Graphics g = snapshot.getGraphics();
      super.paint(g);
    }
    return snapshot;
  }
}

代码示例来源:origin: sc.fiji/TrakEM2_

protected BufferedImage makeImage( final ImageProcessor ip, final FloatProcessor mask )
{
  final BufferedImage transformedImage = new BufferedImage( ip.getWidth(), ip.getHeight(), null == mask ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB );
  final Image img = ip.createImage();
  transformedImage.createGraphics().drawImage( img, 0, 0, null );
  img.flush();
  if (null != mask) {
    transformedImage.getAlphaRaster().setPixels( 0, 0, ip.getWidth(), ip.getHeight(), ( float[] )mask.getPixels() );
  }
  return transformedImage;
}

相关文章