本文整理了Java中java.awt.image.BufferedImage.getRaster()
方法的一些代码示例,展示了BufferedImage.getRaster()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedImage.getRaster()
方法的具体详情如下:
包路径:java.awt.image.BufferedImage
类名称:BufferedImage
方法名:getRaster
暂无
代码示例来源:origin: libgdx/libgdx
public Rect (BufferedImage source, int left, int top, int newWidth, int newHeight, boolean isPatch) {
image = new BufferedImage(source.getColorModel(),
source.getRaster().createWritableChild(left, top, newWidth, newHeight, 0, 0, null),
source.getColorModel().isAlphaPremultiplied(), null);
offsetX = left;
offsetY = top;
regionWidth = newWidth;
regionHeight = newHeight;
originalWidth = source.getWidth();
originalHeight = source.getHeight();
width = newWidth;
height = newHeight;
this.isPatch = isPatch;
}
代码示例来源:origin: stackoverflow.com
public byte[] extractBytes (String ImageName) throws IOException {
// open image
File imgPath = new File(ImageName);
BufferedImage bufferedImage = ImageIO.read(imgPath);
// get DataBufferBytes from Raster
WritableRaster raster = bufferedImage .getRaster();
DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
return ( data.getData() );
}
代码示例来源:origin: stackoverflow.com
private static void copySrcIntoDstAt(final BufferedImage src,
final BufferedImage dst, final int dx, final int dy) {
int[] srcbuf = ((DataBufferInt) src.getRaster().getDataBuffer()).getData();
int[] dstbuf = ((DataBufferInt) dst.getRaster().getDataBuffer()).getData();
int width = src.getWidth();
int height = src.getHeight();
int dstoffs = dx + dy * dst.getWidth();
int srcoffs = 0;
for (int y = 0 ; y < height ; y++ , dstoffs+= dst.getWidth(), srcoffs += width ) {
System.arraycopy(srcbuf, srcoffs , dstbuf, dstoffs, width);
}
}
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
private void getImagePixels() {
int w = image.getWidth();
int h = image.getHeight();
int type = image.getType();
if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR)) {
BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = temp.createGraphics();
g.drawImage(image, 0, 0, null);
image = temp;
}
pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
}
代码示例来源:origin: plantuml/plantuml
private static BufferedImage deepCopy(BufferedImage bi) {
final ColorModel cm = bi.getColorModel();
final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
final WritableRaster raster = bi.copyData(bi.getRaster().createCompatibleWritableRaster());
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public static final ByteBuffer getImageDataFromImage(BufferedImage bufferedImage) {
WritableRaster wr;
DataBuffer db;
BufferedImage bi = new BufferedImage(128, 64, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bi.createGraphics();
g.drawImage(bufferedImage, null, null);
bufferedImage = bi;
wr = bi.getRaster();
db = wr.getDataBuffer();
DataBufferInt dbi = (DataBufferInt) db;
int[] data = dbi.getData();
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(data.length * 4);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
byteBuffer.asIntBuffer().put(data);
byteBuffer.flip();
return byteBuffer;
}
代码示例来源:origin: sarxos/webcam-capture
/**
* Based on answer: https://stackoverflow.com/a/12062505/7030976
*
* @param bgr - byte array in bgr format
* @return new image
*/
private BufferedImage buildImage(byte[] bgr) {
BufferedImage image = new BufferedImage(resolution.width, resolution.height, BufferedImage.TYPE_3BYTE_BGR);
byte[] imageData = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
System.arraycopy(bgr, 0, imageData, 0, bgr.length);
return image;
}
代码示例来源:origin: MovingBlocks/Terasology
@Override
public void render(BufferedImage img, Region region) {
FloraFacet treeFacet = region.getFacet(FloraFacet.class);
Graphics2D g = img.createGraphics();
int width = img.getWidth();
ColorModel colorModel = img.getColorModel();
ColorBlender blender = ColorBlenders.forColorModel(ColorModels.RGBA, colorModel);
DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer();
for (Entry<BaseVector3i, FloraType> entry : treeFacet.getRelativeEntries().entrySet()) {
FloraType treeGen = entry.getValue();
int wx = entry.getKey().getX();
int wz = entry.getKey().getZ();
Color color = colorFunc.apply(treeGen);
int src = color.rgba();
int dst = dataBuffer.getElem(wz * width + wx);
int mix = blender.blend(src, dst);
dataBuffer.setElem(wz * width + wx, mix);
}
g.dispose();
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public static void convertScreenShot2(IntBuffer bgraBuf, BufferedImage out){
WritableRaster wr = out.getRaster();
DataBufferInt db = (DataBufferInt) wr.getDataBuffer();
int[] cpuArray = db.getData();
bgraBuf.clear();
bgraBuf.get(cpuArray);
// int width = wr.getWidth();
// int height = wr.getHeight();
//
// // flip the components the way AWT likes them
// for (int y = 0; y < height / 2; y++){
// for (int x = 0; x < width; x++){
// int inPtr = (y * width + x);
// int outPtr = ((height-y-1) * width + x);
// int pixel = cpuArray[inPtr];
// cpuArray[inPtr] = cpuArray[outPtr];
// cpuArray[outPtr] = pixel;
// }
// }
}
代码示例来源:origin: haraldk/TwelveMonkeys
Raster raster = image instanceof BufferedImage ? ((BufferedImage) image).getRaster() : image.getData();
DataBuffer buf = raster.getDataBuffer();
if (buf instanceof DataBufferByte) {
writePICTData(
0, 0, image.getWidth(), image.getHeight(),
image.getColorModel(), ((DataBufferByte) buf).getData(),
0, image.getWidth()
);
代码示例来源:origin: plantuml/plantuml
/**
* Extracts image pixels into byte array "pixels"
*/
protected void getImagePixels() {
int w = image.getWidth();
int h = image.getHeight();
int type = image.getType();
if ((w != width) || (h != height) || (type != BufferedImage.TYPE_3BYTE_BGR)) {
// create new image with right size/format
BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = temp.createGraphics();
g.drawImage(image, 0, 0, null);
image = temp;
}
pixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
}
代码示例来源:origin: libgdx/libgdx
public Rect (BufferedImage source, int left, int top, int newWidth, int newHeight, boolean isPatch) {
image = new BufferedImage(source.getColorModel(),
source.getRaster().createWritableChild(left, top, newWidth, newHeight, 0, 0, null),
source.getColorModel().isAlphaPremultiplied(), null);
offsetX = left;
offsetY = top;
regionWidth = newWidth;
regionHeight = newHeight;
originalWidth = source.getWidth();
originalHeight = source.getHeight();
width = newWidth;
height = newHeight;
this.isPatch = isPatch;
}
代码示例来源:origin: Dreampie/Resty
public BufferedImage filter(BufferedImage src, BufferedImage dest) {
if (dest == null) {
dest = createCompatibleDestImage(src, null);
}
int width = src.getWidth();
int height = src.getHeight();
int[] inPixels = new int[width * height];
int[] outPixels = new int[width * height];
src.getRaster().getDataElements(0, 0, width, height, inPixels);
filter(inPixels, outPixels, width, height);
dest.getRaster().setDataElements(0, 0, width, height, outPixels);
return dest;
}
代码示例来源:origin: kevin-wayne/algs4
WritableRaster raster = offscreenImage.getRaster();
WritableRaster newRaster;
newRaster = raster.createWritableChild(0, 0, width, height, 0, 0, new int[] {0, 1, 2});
cm.getGreenMask(),
cm.getBlueMask());
BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false, null);
try {
ImageIO.write(rgbBuffer, suffix, file);
代码示例来源:origin: sarxos/webcam-capture
public void rgbFrame(boolean isPrerollFrame, int width, int height, IntBuffer rgb) {
LOG.trace("RGB frame ({}x{}), preroll is {}", width, height, isPrerollFrame);
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
final int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
rgb.get(pixels, 0, width * height);
try {
exchanger.exchange(image);
} catch (InterruptedException e) {
throw new WebcamException("Exchange has been interrupted", e);
}
}
代码示例来源:origin: ivan-vasilev/neuralnetworks
images[i] = new BufferedImage(32, 32, BufferedImage.TYPE_3BYTE_BGR);
byte[] pixels = ((DataBufferByte) images[i].getRaster().getDataBuffer()).getData();
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private Object extractImageData(BufferedImage img){
DataBuffer buf = img.getRaster().getDataBuffer();
switch (buf.getDataType()){
case DataBuffer.TYPE_BYTE:
DataBufferByte byteBuf = (DataBufferByte) buf;
return byteBuf.getData();
case DataBuffer.TYPE_USHORT:
DataBufferUShort shortBuf = (DataBufferUShort) buf;
return shortBuf.getData();
}
return null;
}
代码示例来源:origin: apache/cloudstack
public static void main(String args[]) {
System.setProperty("streamer.Element.debug", "true");
BufferedImageCanvas canvas = new BufferedImageCanvas(4, 4);
Element renderer = new BufferedImagePixelsAdapter("renderer", canvas);
byte[] pixels = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
int[] pixelsLE = new int[] {0x04030201, 0x08070605, 0x0c0b0a09, 0x100f0e0d, 0x04030201, 0x08070605, 0x0c0b0a09, 0x100f0e0d, 0x04030201, 0x08070605,
0x0c0b0a09, 0x100f0e0d, 0x04030201, 0x08070605, 0x0c0b0a09, 0x100f0e0d};
ByteBuffer buf = new ByteBuffer(pixels);
buf.putMetadata(TARGET_X, 0);
buf.putMetadata(TARGET_Y, 0);
buf.putMetadata(WIDTH, 4);
buf.putMetadata(HEIGHT, 4);
buf.putMetadata(PIXEL_FORMAT, RGB888LE32);
renderer.handleData(buf, null);
String actualData = Arrays.toString(((DataBufferInt)canvas.getOfflineImage().getRaster().getDataBuffer()).getData());
String expectedData = Arrays.toString(pixelsLE);
if (!actualData.equals(expectedData))
s_logger.error("Actual image: " + actualData + "\nExpected image: " + expectedData + ".");
}
代码示例来源:origin: MovingBlocks/Terasology
final WritableRaster raster = image.getRaster();
final DataBufferByte dbf = (DataBufferByte) raster.getDataBuffer();
byte[] data = dbf.getData();
final int stride = data.length / (image.getWidth() * image.getHeight());
+ image.getWidth() * image.getHeight() * stride + ", instead of " + data.length);
final ByteBuffer buf = ByteBuffer.allocateDirect(4 * image.getWidth() * image.getHeight());
代码示例来源:origin: libgdx/libgdx
private void generatePremultiplyAlpha(File out){
try {
BufferedImage outImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
float[] color = new float[4];
WritableRaster raster = image.getRaster();
WritableRaster outRaster = outImage.getRaster();
for(int x =0, w = image.getWidth(); x< w; ++x)
for(int y =0, h = image.getHeight(); y< h; ++y){
raster.getPixel(x, y, color);
float alpha = color[3]/255f;
for(int i=0;i < 3; ++i)
color[i] *= alpha;
outRaster.setPixel(x, y, color);
}
ImageIO.write(outImage, "png", out);
} catch (IOException e) {
e.printStackTrace();
}
}
内容来源于网络,如有侵权,请联系作者删除!