本文整理汇总了Java中java.awt.image.Raster类的典型用法代码示例。如果您正苦于以下问题:Java Raster类的具体用法?Java Raster怎么用?Java Raster使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Raster类属于java.awt.image包,在下文中一共展示了Raster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import java.awt.image.Raster; //导入依赖的package包/类
@Override
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
RenderedImage img = image.getRenderedImage();
if (stream == null) {
throw new IOException("Set an output first!");
}
if (param == null) {
param = getDefaultWriteParam();
}
Rectangle sourceRegion = new Rectangle(0, 0, img.getWidth(), img.getHeight());
if (param.getSourceRegion() != null) {
sourceRegion = sourceRegion.intersection(param.getSourceRegion());
}
Raster raster = img.getData(sourceRegion);
int quality = 85;
if (param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
quality = (int) (param.getCompressionQuality() * 100);
}
try {
stream.write(lib.encode(raster, quality).array());
} catch (TurboJpegException e) {
throw new IOException(e);
}
}
示例2: getImage
import java.awt.image.Raster; //导入依赖的package包/类
@Override
public BufferedImage getImage()
{
ByteBuffer buffer = this.getImageBytes();
if (buffer == null)
{
LOG.error("Images bytes buffer is null!");
return null;
}
byte[] bytes = new byte[this.size.width * this.size.height * 3];
byte[][] data = new byte[][] { bytes };
buffer.get(bytes);
DataBufferByte dbuf = new DataBufferByte(data, bytes.length, OFFSET);
WritableRaster raster = Raster.createWritableRaster(this.smodel, dbuf, null);
BufferedImage bi = new BufferedImage(this.cmodel, raster, false, null);
bi.flush();
return bi;
}
示例3: setDataElements
import java.awt.image.Raster; //导入依赖的package包/类
/**
* Stores the Raster data at the specified location.
* @param dstX The absolute X coordinate of the destination pixel
* that will receive a copy of the upper-left pixel of the
* inRaster
* @param dstY The absolute Y coordinate of the destination pixel
* that will receive a copy of the upper-left pixel of the
* inRaster
* @param width The number of pixels to store horizontally
* @param height The number of pixels to store vertically
* @param inRaster Raster of data to place at x,y location.
*/
private void setDataElements(int dstX, int dstY,
int width, int height,
Raster inRaster) {
// Assume bounds checking has been performed previously
if (width <= 0 || height <= 0) {
return;
}
int srcOffX = inRaster.getMinX();
int srcOffY = inRaster.getMinY();
Object tdata = null;
// // REMIND: Do something faster!
// if (inRaster instanceof ByteBandedRaster) {
// }
for (int startY=0; startY < height; startY++) {
// Grab one scanline at a time
tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
width, 1, tdata);
setDataElements(dstX, dstY+startY, width, 1, tdata);
}
}
示例4: putCachedRaster
import java.awt.image.Raster; //导入依赖的package包/类
static synchronized void putCachedRaster(ColorModel cm, Raster ras) {
if (cached != null) {
Raster cras = (Raster) cached.get();
if (cras != null) {
int cw = cras.getWidth();
int ch = cras.getHeight();
int iw = ras.getWidth();
int ih = ras.getHeight();
if (cw >= iw && ch >= ih) {
return;
}
if (cw * ch >= iw * ih) {
return;
}
}
}
cachedModel = cm;
cached = new WeakReference<>(ras);
}
示例5: getRaster
import java.awt.image.Raster; //导入依赖的package包/类
/**
* Return a Raster containing the colors generated for the graphics
* operation.
* @param x,y,w,h The area in device space for which colors are
* generated.
*/
public Raster getRaster(int x, int y, int w, int h) {
double rowrel = (x - x1) * dx + (y - y1) * dy;
Raster rast = saved;
if (rast == null || rast.getWidth() < w || rast.getHeight() < h) {
rast = getCachedRaster(model, w, h);
saved = rast;
}
IntegerComponentRaster irast = (IntegerComponentRaster) rast;
int off = irast.getDataOffset(0);
int adjust = irast.getScanlineStride() - w;
int[] pixels = irast.getDataStorage();
if (cyclic) {
cycleFillRaster(pixels, off, adjust, w, h, rowrel, dx, dy);
} else {
clipFillRaster(pixels, off, adjust, w, h, rowrel, dx, dy);
}
irast.markDirty();
return rast;
}
示例6: gethISTNode
import java.awt.image.Raster; //导入依赖的package包/类
private IIOMetadataNode gethISTNode(BufferedImage bi) {
IndexColorModel icm = (IndexColorModel)bi.getColorModel();
int mapSize = icm.getMapSize();
int[] hist = new int[mapSize];
Arrays.fill(hist, 0);
Raster r = bi.getData();
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
int s = r.getSample(x, y, 0);
hist[s] ++;
}
}
IIOMetadataNode hIST = new IIOMetadataNode("hIST");
for (int i = 0; i < hist.length; i++) {
IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
n.setAttribute("index", "" + i);
n.setAttribute("value", "" + hist[i]);
hIST.appendChild(n);
}
return hIST;
}
示例7: getRaster
import java.awt.image.Raster; //导入依赖的package包/类
public synchronized Raster getRaster(int x, int y, int w, int h) {
WritableRaster t = savedTile;
if (t == null || w > t.getWidth() || h > t.getHeight()) {
t = getColorModel().createCompatibleWritableRaster(w, h);
IntegerComponentRaster icr = (IntegerComponentRaster) t;
Arrays.fill(icr.getDataStorage(), color);
// Note - markDirty is probably unnecessary since icr is brand new
icr.markDirty();
if (w <= 64 && h <= 64) {
savedTile = t;
}
}
return t;
}
示例8: Blit
import java.awt.image.Raster; //导入依赖的package包/类
public void Blit(SurfaceData srcData,
SurfaceData dstData,
Composite comp,
Region clip,
int srcx, int srcy,
int dstx, int dsty,
int width, int height)
{
ColorModel srcCM = srcData.getColorModel();
ColorModel dstCM = dstData.getColorModel();
// REMIND: Should get RenderingHints from sg2d
CompositeContext ctx = comp.createContext(srcCM, dstCM,
new RenderingHints(null));
Raster srcRas = srcData.getRaster(srcx, srcy, width, height);
WritableRaster dstRas =
(WritableRaster) dstData.getRaster(dstx, dsty, width, height);
if (clip == null) {
clip = Region.getInstanceXYWH(dstx, dsty, width, height);
}
int span[] = {dstx, dsty, dstx+width, dsty+height};
SpanIterator si = clip.getSpanIterator(span);
srcx -= dstx;
srcy -= dsty;
while (si.nextSpan(span)) {
int w = span[2] - span[0];
int h = span[3] - span[1];
Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1],
w, h, 0, 0, null);
WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1],
w, h, 0, 0, null);
ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas);
}
ctx.dispose();
}
示例9: getRaster
import java.awt.image.Raster; //导入依赖的package包/类
/**
* Return a Raster containing the colors generated for the graphics
* operation.
* @param x,y,w,h The area in device space for which colors are
* generated.
*/
public Raster getRaster(int x, int y, int w, int h) {
if (outRas == null ||
outRas.getWidth() < w ||
outRas.getHeight() < h)
{
// If h==1, we will probably get lots of "scanline" rects
outRas = makeRaster((h == 1 ? Math.max(w, maxWidth) : w), h);
}
double X = mod(xOrg + x * incXAcross + y * incXDown, bWidth);
double Y = mod(yOrg + x * incYAcross + y * incYDown, bHeight);
setRaster((int) X, (int) Y, fractAsInt(X), fractAsInt(Y),
w, h, bWidth, bHeight,
colincx, colincxerr,
colincy, colincyerr,
rowincx, rowincxerr,
rowincy, rowincyerr);
SunWritableRaster.markDirty(outRas);
return outRas;
}
示例10: setDataElements
import java.awt.image.Raster; //导入依赖的package包/类
/**
* Stores the Raster data at the specified location.
* @param dstX The absolute X coordinate of the destination pixel
* that will receive a copy of the upper-left pixel of the
* inRaster
* @param dstY The absolute Y coordinate of the destination pixel
* that will receive a copy of the upper-left pixel of the
* inRaster
* @param width The number of pixels to store horizontally
* @param height The number of pixels to store vertically
* @param inRaster Raster of data to place at x,y location.
*/
private void setDataElements(int dstX, int dstY,
int width, int height,
Raster inRaster) {
// Assume bounds checking has been performed previously
if (width <= 0 || height <= 0) {
return;
}
// Write inRaster (minX, minY) to (dstX, dstY)
int srcOffX = inRaster.getMinX();
int srcOffY = inRaster.getMinY();
Object tdata = null;
// // REMIND: Do something faster!
// if (inRaster instanceof ShortComponentRaster) {
// }
for (int startY=0; startY < height; startY++) {
// Grab one scanline at a time
tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
width, 1, tdata);
setDataElements(dstX, dstY + startY, width, 1, tdata);
}
}
示例11: bufferAsJpgString
import java.awt.image.Raster; //导入依赖的package包/类
/**
* Converts raw data into JPG image and encode it into Base64 string for sending it to the JS client
*
* @param rawImg
* raw image bytes
* @return Base64 encoded string with JPG image
*/
private String bufferAsJpgString(byte[] rawImg) {
int[] pixels = new int[rawImg.length];
for (int i = 0; i < rawImg.length; i++) {
pixels[i] = (int) rawImg[i];
}
DataBufferInt buffer = new DataBufferInt(pixels, pixels.length);
WritableRaster raster = Raster.createPackedRaster(buffer, IMG_SIZE, IMG_SIZE, IMG_SIZE, BAND_MASKS, null);
ColorModel cm = ColorModel.getRGBdefault();
BufferedImage image = new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
byte[] imgBytes = null;
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ImageIO.write(image, "JPG", baos);
baos.flush();
imgBytes = baos.toByteArray();
} catch (IOException e) {
// TODO log exception
}
byte[] encoded = Base64.getEncoder().encode(imgBytes);
return new String(encoded);
}
示例12: setDataElements
import java.awt.image.Raster; //导入依赖的package包/类
/**
* Stores the Raster data at the specified location.
* An ArrayIndexOutOfBounds exception will be thrown at runtime
* if the pixel coordinates are out of bounds.
* @param x The X coordinate of the pixel location.
* @param y The Y coordinate of the pixel location.
* @param inRaster Raster of data to place at x,y location.
*/
public void setDataElements(int x, int y, Raster inRaster) {
// Check if we can use fast code
if (!(inRaster instanceof BytePackedRaster) ||
((BytePackedRaster)inRaster).pixelBitStride != pixelBitStride) {
super.setDataElements(x, y, inRaster);
return;
}
int srcOffX = inRaster.getMinX();
int srcOffY = inRaster.getMinY();
int dstOffX = srcOffX + x;
int dstOffY = srcOffY + y;
int width = inRaster.getWidth();
int height = inRaster.getHeight();
if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
(dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) {
throw new ArrayIndexOutOfBoundsException
("Coordinate out of bounds!");
}
setDataElements(dstOffX, dstOffY,
srcOffX, srcOffY,
width, height,
(BytePackedRaster)inRaster);
}
示例13: setDataElements
import java.awt.image.Raster; //导入依赖的package包/类
/**
* Stores the Raster data at the specified location.
* @param dstX The absolute X coordinate of the destination pixel
* that will receive a copy of the upper-left pixel of the
* inRaster
* @param dstY The absolute Y coordinate of the destination pixel
* that will receive a copy of the upper-left pixel of the
* inRaster
* @param width The number of pixels to store horizontally
* @param height The number of pixels to store vertically
* @param inRaster Raster of data to place at x,y location.
*/
private void setDataElements(int dstX, int dstY,
int width, int height,
Raster inRaster) {
// Assume bounds checking has been performed previously
if (width <= 0 || height <= 0) {
return;
}
// Write inRaster (minX, minY) to (dstX, dstY)
int srcOffX = inRaster.getMinX();
int srcOffY = inRaster.getMinY();
Object tdata = null;
// REMIND: Do something faster!
// if (inRaster instanceof ShortInterleavedRaster) {
// }
for (int startY=0; startY < height; startY++) {
// Grab one scanline at a time
tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
width, 1, tdata);
setDataElements(dstX, dstY + startY, width, 1, tdata);
}
}
示例14: setDataElements
import java.awt.image.Raster; //导入依赖的package包/类
/**
* Stores the Raster data at the specified location.
* @param dstX The absolute X coordinate of the destination pixel
* that will receive a copy of the upper-left pixel of the
* inRaster
* @param dstY The absolute Y coordinate of the destination pixel
* that will receive a copy of the upper-left pixel of the
* inRaster
* @param width The number of pixels to store horizontally
* @param height The number of pixels to store vertically
* @param inRaster Raster of data to place at x,y location.
*/
private void setDataElements(int dstX, int dstY,
int width, int height,
Raster inRaster) {
// Assume bounds checking has been performed previously
if (width <= 0 || height <= 0) {
return;
}
// Write inRaster (minX, minY) to (dstX, dstY)
int srcOffX = inRaster.getMinX();
int srcOffY = inRaster.getMinY();
Object tdata = null;
// // REMIND: Do something faster!
// if (inRaster instanceof ShortBandedRaster) {
// }
for (int startY=0; startY < height; startY++) {
// Grab one scanline at a time
tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
width, 1, tdata);
setDataElements(dstX, dstY + startY, width, 1, tdata);
}
}
示例15: getPixels
import java.awt.image.Raster; //导入依赖的package包/类
/**
* <p>Returns an array of pixels, stored as integers, from a
* <code>BufferedImage</code>. The pixels are grabbed from a rectangular
* area defined by a location and two dimensions. Calling this method on
* an image of type different from <code>BufferedImage.TYPE_INT_ARGB</code>
* and <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image.</p>
*
* @param img the source image
* @param x the x location at which to start grabbing pixels
* @param y the y location at which to start grabbing pixels
* @param w the width of the rectangle of pixels to grab
* @param h the height of the rectangle of pixels to grab
* @param pixels a pre-allocated array of pixels of size w*h; can be null
* @return <code>pixels</code> if non-null, a new array of integers
* otherwise
* @throws IllegalArgumentException is <code>pixels</code> is non-null and
* of length < w*h
*/
public static int[] getPixels(BufferedImage img,
int x, int y, int w, int h, int[] pixels) {
if (w == 0 || h == 0) {
return new int[0];
}
if (pixels == null) {
pixels = new int[w * h];
} else if (pixels.length < w * h) {
throw new IllegalArgumentException("pixels array must have a length" +
" >= w*h");
}
int imageType = img.getType();
if (imageType == BufferedImage.TYPE_INT_ARGB ||
imageType == BufferedImage.TYPE_INT_RGB) {
Raster raster = img.getRaster();
return (int[]) raster.getDataElements(x, y, w, h, pixels);
}
// Unmanages the image
return img.getRGB(x, y, w, h, pixels, 0, w);
}