本文整理匯總了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;
}