本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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();
}
示例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);
}
示例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();
}
示例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;
}