本文整理汇总了Java中java.awt.image.DataBufferByte.setElem方法的典型用法代码示例。如果您正苦于以下问题:Java DataBufferByte.setElem方法的具体用法?Java DataBufferByte.setElem怎么用?Java DataBufferByte.setElem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.DataBufferByte
的用法示例。
在下文中一共展示了DataBufferByte.setElem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSubImage
import java.awt.image.DataBufferByte; //导入方法依赖的package包/类
/**
* Build the sub-image that corresponds to the provided row of features.
*
* @param row the flat row of pixel values
* @return the bufferedImage
*/
public static BufferedImage buildSubImage (INDArray row)
{
// Build a gray image with vector values
BufferedImage grayImg = new BufferedImage(
CONTEXT_WIDTH,
CONTEXT_HEIGHT,
BufferedImage.TYPE_BYTE_GRAY);
WritableRaster raster = grayImg.getRaster();
DataBuffer buffer = raster.getDataBuffer();
DataBufferByte byteBuffer = (DataBufferByte) buffer;
for (int r = 0; r < CONTEXT_HEIGHT; r++) {
int offset = r * CONTEXT_WIDTH;
for (int c = 0; c < CONTEXT_WIDTH; c++) {
int i = offset + c;
int val = (int) Math.rint(row.getDouble(i));
val = 255 - val; // Inversion
byteBuffer.setElem(i, val);
}
}
// Draw colored reference lines on top of image
BufferedImage colorImg = new BufferedImage(
CONTEXT_WIDTH,
CONTEXT_HEIGHT,
BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g = colorImg.createGraphics();
g.drawImage(grayImg, null, null);
g.setColor(CROSS_COLOR);
g.drawLine(CONTEXT_WIDTH / 2, 0, CONTEXT_WIDTH / 2, CONTEXT_HEIGHT);
g.drawLine(0, CONTEXT_HEIGHT / 2, CONTEXT_WIDTH, CONTEXT_HEIGHT / 2);
g.dispose();
return colorImg;
}