本文整理汇总了Java中java.awt.image.DataBufferByte.getData方法的典型用法代码示例。如果您正苦于以下问题:Java DataBufferByte.getData方法的具体用法?Java DataBufferByte.getData怎么用?Java DataBufferByte.getData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.DataBufferByte
的用法示例。
在下文中一共展示了DataBufferByte.getData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matToBufferedImage
import java.awt.image.DataBufferByte; //导入方法依赖的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;
}
示例2: bufferedImage
import java.awt.image.DataBufferByte; //导入方法依赖的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;
}
示例3: getByteData
import java.awt.image.DataBufferByte; //导入方法依赖的package包/类
/**
* Obtains the data from the raster of the given image as a byte array.
*
* @param image The image
* @return The image data
* @throws IllegalArgumentException If the given image is not backed by a
* DataBufferByte. Usually, only BufferedImages of with the types
* BufferedImage.TYPE_BYTE_* have a DataBufferByte
*/
public static byte[] getByteData(BufferedImage image) {
DataBuffer dataBuffer = image.getRaster().getDataBuffer();
if (!(dataBuffer instanceof DataBufferByte)) {
throw new IllegalArgumentException(
"Image does not contain a DataBufferByte");
}
DataBufferByte dataBufferByte = (DataBufferByte) dataBuffer;
byte data[] = dataBufferByte.getData();
return data;
}
示例4: readFrames
import java.awt.image.DataBufferByte; //导入方法依赖的package包/类
protected void readFrames(InputStream inputStream) {
try {
long t0=System.currentTimeMillis()-1; // -1: Avoid div by zero in very fast cases
while(true)
{
BufferedImage im=frames[writePtr];
DataBufferByte b=(DataBufferByte)im.getRaster().getDataBuffer();
byte[] data=b.getData();
int at=0;
while(at<data.length)
{
int n=inputStream.read(data, at, data.length-at);
if(n<0)
{
throw new EOFException();
}
at+=n;
}
nRead++;
writePtr++;
writePtr%=frames.length;
long t=System.currentTimeMillis();
fps=((double)nRead)/(t-t0)*1000;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例5: getByteData
import java.awt.image.DataBufferByte; //导入方法依赖的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.DataBufferByte; //导入方法依赖的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.DataBufferByte; //导入方法依赖的package包/类
private byte[] get_byte_data(BufferedImage image)
{
WritableRaster raster = image.getRaster();
DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
return buffer.getData();
}