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

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

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

BufferedImage.coerceData介绍

暂无

代码示例

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

image.coerceData(true);
return image;

代码示例来源:origin: io.playn/playn-java-base

/** Converts the given image into a format for quick upload to the GPU. */
static BufferedImage convertImage (BufferedImage image) {
 switch (image.getType()) {
 case BufferedImage.TYPE_INT_ARGB_PRE:
  return image; // Already good to go
 case BufferedImage.TYPE_4BYTE_ABGR:
  image.coerceData(true); // Just premultiply the alpha and it's fine
  return image;
 }
 // Didn't know an easy thing to do, so create a whole new image in our preferred format
 BufferedImage convertedImage = new BufferedImage(image.getWidth(), image.getHeight(),
                          BufferedImage.TYPE_INT_ARGB_PRE);
 Graphics2D g = convertedImage.createGraphics();
 g.setColor(new java.awt.Color(0f, 0f, 0f, 0f));
 g.fillRect(0, 0, image.getWidth(), image.getHeight());
 g.drawImage(image, 0, 0, null);
 g.dispose();
 return convertedImage;
}

代码示例来源:origin: threerings/playn

/** Converts the given image into a format for quick upload to the GPU. */
static BufferedImage convertImage (BufferedImage image) {
 switch (image.getType()) {
 case BufferedImage.TYPE_INT_ARGB_PRE:
  return image; // Already good to go
 case BufferedImage.TYPE_4BYTE_ABGR:
  image.coerceData(true); // Just premultiply the alpha and it's fine
  return image;
 }
 // Didn't know an easy thing to do, so create a whole new image in our preferred format
 BufferedImage convertedImage = new BufferedImage(image.getWidth(), image.getHeight(),
                          BufferedImage.TYPE_INT_ARGB_PRE);
 Graphics g = convertedImage.getGraphics();
 g.setColor(new Color(0f, 0f, 0f, 0f));
 g.fillRect(0, 0, image.getWidth(), image.getHeight());
 g.drawImage(image, 0, 0, null);
 return convertedImage;
}

代码示例来源:origin: com.googlecode.playn/playn-java

/** Converts the given image into a format for quick upload to the GPU. */
static BufferedImage convertImage (BufferedImage image) {
 switch (image.getType()) {
 case BufferedImage.TYPE_INT_ARGB_PRE:
  return image; // Already good to go
 case BufferedImage.TYPE_4BYTE_ABGR:
  image.coerceData(true); // Just premultiply the alpha and it's fine
  return image;
 }
 // Didn't know an easy thing to do, so create a whole new image in our preferred format
 BufferedImage convertedImage = new BufferedImage(image.getWidth(), image.getHeight(),
                          BufferedImage.TYPE_INT_ARGB_PRE);
 Graphics g = convertedImage.getGraphics();
 g.setColor(new Color(0f, 0f, 0f, 0f));
 g.fillRect(0, 0, image.getWidth(), image.getHeight());
 g.drawImage(image, 0, 0, null);
 return convertedImage;
}

代码示例来源:origin: google/sagetv

public static void fixAlphaInconsistency(java.awt.Image img)
{
 if (img instanceof java.awt.image.BufferedImage)
 {
  java.awt.image.BufferedImage bi = (java.awt.image.BufferedImage) img;
  if (bi.getType() == java.awt.image.BufferedImage.TYPE_INT_ARGB ||
    bi.getType() == java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE)
  {
   if ((bi.getType() == java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE) != bi.isAlphaPremultiplied())
   {
    if (Sage.DBG) System.out.println("Fixing alpha state for image so type matches color model:" + img);
    bi.coerceData(bi.getType() == java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE);
   }
  }
 }
}

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

/** Converts the given image into a format for quick upload to the GPU. */
static BufferedImage convertImage (BufferedImage image) {
 switch (image.getType()) {
 case BufferedImage.TYPE_INT_ARGB_PRE:
  return image; // Already good to go
 case BufferedImage.TYPE_4BYTE_ABGR:
  image.coerceData(true); // Just premultiply the alpha and it's fine
  return image;
 }
 // Didn't know an easy thing to do, so create a whole new image in our preferred format
 BufferedImage convertedImage = new BufferedImage(image.getWidth(), image.getHeight(),
                          BufferedImage.TYPE_INT_ARGB_PRE);
 Graphics2D g = convertedImage.createGraphics();
 g.setColor(new java.awt.Color(0f, 0f, 0f, 0f));
 g.fillRect(0, 0, image.getWidth(), image.getHeight());
 g.drawImage(image, 0, 0, null);
 g.dispose();
 return convertedImage;
}

代码示例来源:origin: google/sagetv

public java.nio.ByteBuffer getBufferFromBI(java.awt.image.BufferedImage bi)
{
 java.nio.ByteBuffer imageBuffer = null;
 java.awt.image.WritableRaster raster;
 java.awt.image.BufferedImage texImage;
 raster = java.awt.image.Raster.createInterleavedRaster(java.awt.image.DataBuffer.TYPE_BYTE,
   bi.getWidth(), bi.getHeight(), 4, null);
 texImage = new java.awt.image.BufferedImage(glAlphaColorModel,raster,true,new java.util.Hashtable());
 java.awt.Graphics g = texImage.getGraphics();
 g.drawImage(bi,0,0,null);
 g.dispose();
 // Make sure that alpha is pre-multiplied
 texImage.coerceData(true);
 byte[] data = ((java.awt.image.DataBufferByte) texImage.getRaster().getDataBuffer()).getData();
 imageBuffer = java.nio.ByteBuffer.allocateDirect(data.length);
 imageBuffer.order(java.nio.ByteOrder.nativeOrder());
 imageBuffer.put(data, 0, data.length);
 imageBuffer.flip();
 return imageBuffer;
}

代码示例来源:origin: google/sagetv

public RawImage(java.awt.image.BufferedImage bi)
{
 if (bi.getType() != java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE && bi.getType() != java.awt.image.BufferedImage.TYPE_INT_ARGB)
 {
  throw new IllegalArgumentException("Can only create RawImages from ARGB_PRE BIs, was given: " + bi.getType());
 }
 if (!bi.isAlphaPremultiplied())
 {
  //if (sage.Sage.DBG) System.out.println("Premultiplying alpha channel for RawImage creation from Java image");
  bi.coerceData(true);
 }
 width = bi.getWidth();
 height = bi.getHeight();
 hasAlpha = true;
 stride = 4*width;
 dataBuff = java.nio.ByteBuffer.allocateDirect(4*width*height);
 dataBuff.asIntBuffer().put(((java.awt.image.DataBufferInt) bi.getRaster().getDataBuffer()).getData());
 dataBuff.limit(4*width*height);
 internalAlloc = true;
}

代码示例来源:origin: unascribed-archive/Visage

public static void upload(BufferedImage img, int format, int tex) {
  int width = img.getWidth();
  int height = img.getHeight();
  if (Visage.trace) Visage.log.finest("Uploading "+width+"x"+height+" ("+(width*height)+" pixel) image");
  
  BufferedImage unindexed = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
  
  int[] argb = new int[width*height];
  img.getRGB(0, 0, width, height, argb, 0, width);
  
  unindexed.setRGB(0, 0, width, height, argb, 0, width);
  unindexed.coerceData(true);
  unindexed.getRGB(0, 0, width, height, argb, 0, width);
  
  IntBuffer buf = BufferUtils.createIntBuffer(width*height);
  buf.put(argb);
  buf.flip();
  
  glBindTexture(GL_TEXTURE_2D, tex);
  glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, buf);
  
  checkGLError();
}

代码示例来源:origin: org.rrd4j/rrd4j

void makeImage(Object stream, ImageWriter writer, ImageWriteParam iwp) throws IOException {
  BufferedImage outputImage = img; 
  ImageWriterSpi imgProvider = writer.getOriginatingProvider();
  img.coerceData(false);
  // Some format can't manage 16M colors images
  // JPEG don't like transparency
  if (! imgProvider.canEncodeImage(outputImage) || "image/jpeg".equals(imgProvider.getMIMETypes()[0].toLowerCase())) {
    int w = img.getWidth();
    int h = img.getHeight();
    outputImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    outputImage.getGraphics().drawImage(img, 0, 0, w, h, null);
    if (! imgProvider.canEncodeImage(outputImage)) {
      throw new RuntimeException("Invalid image type");
    }
  }
  if (! imgProvider.canEncodeImage(outputImage)) {
    throw new RuntimeException("Invalid image type");
  }
  try (ImageOutputStream imageStream = ImageIO.createImageOutputStream(stream)) {
    writer.setOutput(imageStream);
    writer.write(null, new IIOImage(outputImage, null, null), iwp);
    imageStream.flush();
  } catch (IOException e) {
    writer.abort();
    throw e;
  } finally {
    writer.dispose();
  }
}

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

image.coerceData(true);
return image;

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

buffer.coerceData(true);

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

image.coerceData(true);
return image;

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

image.coerceData(true);
return image;

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

image.coerceData(true);
return image;

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

image.coerceData(true);
return image;

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

image.coerceData(true);
return image;

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

image.coerceData(true);
return image;

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

image.coerceData(true);
return image;

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

image.coerceData(true);
return image;

相关文章