當前位置: 首頁>>代碼示例>>Java>>正文


Java DataBufferByte.setElem方法代碼示例

本文整理匯總了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;
}
 
開發者ID:Audiveris,項目名稱:omr-dataset-tools,代碼行數:43,代碼來源:SubImages.java


注:本文中的java.awt.image.DataBufferByte.setElem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。