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