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


Java WritableRaster.getDataBuffer方法代碼示例

本文整理匯總了Java中java.awt.image.WritableRaster.getDataBuffer方法的典型用法代碼示例。如果您正苦於以下問題:Java WritableRaster.getDataBuffer方法的具體用法?Java WritableRaster.getDataBuffer怎麽用?Java WritableRaster.getDataBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.image.WritableRaster的用法示例。


在下文中一共展示了WritableRaster.getDataBuffer方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildSubImage

import java.awt.image.WritableRaster; //導入方法依賴的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

示例2: matToBufferedImage

import java.awt.image.WritableRaster; //導入方法依賴的package包/類
public BufferedImage matToBufferedImage(Mat mat) {

        if (mat.height() > 0 && mat.width() > 0) {
            BufferedImage image = new BufferedImage(mat.width(), mat.height(), BufferedImage.TYPE_3BYTE_BGR);
            WritableRaster raster = image.getRaster();
            DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer();
            byte[] data = dataBuffer.getData();
            mat.get(0, 0, data);
            return image;
        }
        return null;
    }
 
開發者ID:Plasmoxy,項目名稱:AquamarineLake,代碼行數:13,代碼來源:DrawPanel.java

示例3: bufferedImage

import java.awt.image.WritableRaster; //導入方法依賴的package包/類
public BufferedImage bufferedImage(Mat mat) {

        if (mat.height() > 0 && mat.width() > 0) {
            BufferedImage image = new BufferedImage(mat.width(), mat.height(), BufferedImage.TYPE_3BYTE_BGR);
            WritableRaster raster = image.getRaster();
            DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer();
            byte[] data = dataBuffer.getData();
            mat.get(0, 0, data);
            return image;
        }
        return null;
    }
 
開發者ID:Plasmoxy,項目名稱:AquamarineLake,代碼行數:13,代碼來源:DrawPanel.java

示例4: compose

import java.awt.image.WritableRaster; //導入方法依賴的package包/類
public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
    int w = src.getWidth();
    int h = src.getHeight();

    DataBufferInt srcDB = (DataBufferInt) src.getDataBuffer();
    DataBufferInt dstOutDB = (DataBufferInt) dstOut.getDataBuffer();
    int srcRGB[] = srcDB.getBankData()[0];
    int dstOutRGB[] = dstOutDB.getBankData()[0];
    int srcOffset = srcDB.getOffset();
    int dstOutOffset = dstOutDB.getOffset();
    int srcScanStride = ((SinglePixelPackedSampleModel) src.getSampleModel()).getScanlineStride();
    int dstOutScanStride = ((SinglePixelPackedSampleModel) dstOut.getSampleModel()).getScanlineStride();
    int srcAdjust = srcScanStride - w;
    int dstOutAdjust = dstOutScanStride - w;

    int si = srcOffset;
    int doi = dstOutOffset;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            dstOutRGB[doi] = srcRGB[si] ^ 0x00ffffff;
            si++;
            doi++;
        }

        si += srcAdjust;
        doi += dstOutAdjust;
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:30,代碼來源:CustomCompositeTest.java

示例5: getByteData

import java.awt.image.WritableRaster; //導入方法依賴的package包/類
/**
 * @param userSpaceImage
 * @return byte array of supplied image
 */
public byte[] getByteData(BufferedImage userSpaceImage) {
    WritableRaster raster = userSpaceImage.getRaster();
    DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
    return buffer.getData();
}
 
開發者ID:varunon9,項目名稱:Image-Stegano,代碼行數:10,代碼來源:ImageUtility.java

示例6: imageToPlatformBytes

import java.awt.image.WritableRaster; //導入方法依賴的package包/類
@Override
protected byte[] imageToPlatformBytes(Image image, long format)
        throws IOException {
    String mimeType = null;
    if (format == CF_PNG) {
        mimeType = "image/png";
    } else if (format == CF_JFIF) {
        mimeType = "image/jpeg";
    }
    if (mimeType != null) {
        return imageToStandardBytes(image, mimeType);
    }

    int width = 0;
    int height = 0;

    if (image instanceof ToolkitImage) {
        ImageRepresentation ir = ((ToolkitImage)image).getImageRep();
        ir.reconstruct(ImageObserver.ALLBITS);
        width = ir.getWidth();
        height = ir.getHeight();
    } else {
        width = image.getWidth(null);
        height = image.getHeight(null);
    }

    // Fix for 4919639.
    // Some Windows native applications (e.g. clipbrd.exe) do not handle
    // 32-bpp DIBs correctly.
    // As a workaround we switched to 24-bpp DIBs.
    // MSDN prescribes that the bitmap array for a 24-bpp should consist of
    // 3-byte triplets representing blue, green and red components of a
    // pixel respectively. Additionally each scan line must be padded with
    // zeroes to end on a LONG data-type boundary. LONG is always 32-bit.
    // We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR
    // with non-default scanline stride and pass the resulting data buffer
    // to the native code to fill the BITMAPINFO structure.
    int mod = (width * 3) % 4;
    int pad = mod > 0 ? 4 - mod : 0;

    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = {8, 8, 8};
    int[] bOffs = {2, 1, 0};
    ColorModel colorModel =
            new ComponentColorModel(cs, nBits, false, false,
                    Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
    WritableRaster raster =
            Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height,
                    width * 3 + pad, 3, bOffs, null);

    BufferedImage bimage = new BufferedImage(colorModel, raster, false, null);

    // Some Windows native applications (e.g. clipbrd.exe) do not understand
    // top-down DIBs.
    // So we flip the image vertically and create a bottom-up DIB.
    AffineTransform imageFlipTransform =
            new AffineTransform(1, 0, 0, -1, 0, height);

    Graphics2D g2d = bimage.createGraphics();

    try {
        g2d.drawImage(image, imageFlipTransform, null);
    } finally {
        g2d.dispose();
    }

    DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();

    byte[] imageData = buffer.getData();
    return imageDataToPlatformImageBytes(imageData, width, height, format);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:72,代碼來源:WDataTransferer.java

示例7: get_byte_data

import java.awt.image.WritableRaster; //導入方法依賴的package包/類
private byte[] get_byte_data(BufferedImage image)
{
        WritableRaster raster   = image.getRaster();
        DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
        return buffer.getData();
}
 
開發者ID:lemon65,項目名稱:Crypto,代碼行數:7,代碼來源:Steganography.java

示例8: doGetDataFrom

import java.awt.image.WritableRaster; //導入方法依賴的package包/類
private static int[] doGetDataFrom(final BufferedImage bufferedImage) {
	final WritableRaster writableRaster = bufferedImage.getRaster();
	
	final DataBuffer dataBuffer = writableRaster.getDataBuffer();
	
	final DataBufferInt dataBufferInt = DataBufferInt.class.cast(dataBuffer);
	
	final int[] data = dataBufferInt.getData();
	
	return data;
}
 
開發者ID:macroing,項目名稱:Dayflower-Path-Tracer,代碼行數:12,代碼來源:ImageTexture.java


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