本文整理汇总了Java中java.awt.image.BufferedImage.getRaster方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage.getRaster方法的具体用法?Java BufferedImage.getRaster怎么用?Java BufferedImage.getRaster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.BufferedImage
的用法示例。
在下文中一共展示了BufferedImage.getRaster方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: girar
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public BufferedImage girar(BufferedImage img, PosicoesDTO posicoes) {
WritableRaster raster = img.getRaster();
BufferedImage newImage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
WritableRaster rasterNewImage = newImage.getRaster();
int pixels[] = new int[4];
for (int i = posicoes.getX1(); i < posicoes.getX2(); i++) {
for (int j = posicoes.getY1(); j < posicoes.getY2(); j++) {
raster.getPixel(i, j, pixels);
rasterNewImage.setPixel(i, img.getHeight() - j, pixels);
}
}
newImage.setData(rasterNewImage);
return newImage;
}
示例2: fromColorCubeMatrix
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
* Converts a color cube matrix into a BufferedImage. See {@link #toColorCubeMatrix(BufferedImage)} for the
* format details of the color cube matrix.
*
* @param matrix The matrix to convert into an image
* @return The BufferedImage resulting from the given color cube matrix
*/
private static BufferedImage fromColorCubeMatrix(double[][][] matrix) {
BufferedImage restored = new BufferedImage(matrix[0].length, matrix.length, BufferedImage.TYPE_INT_ARGB);
WritableRaster raster = restored.getRaster();
for (int y = 0; y < matrix.length; y++) {
for (int x = 0; x < matrix[y].length; x++) {
double[] pixel = matrix[y][x];
pixel[0] *= 255;
pixel[1] *= 255;
pixel[2] *= 255;
pixel[3] = matrix[y][x][3];
pixel[0] = pixel[0] < 0 ? 0 : pixel[0] > 255 ? 255 : pixel[0];
pixel[1] = pixel[1] < 0 ? 0 : pixel[1] > 255 ? 255 : pixel[1];
pixel[2] = pixel[2] < 0 ? 0 : pixel[2] > 255 ? 255 : pixel[2];
raster.setPixel(x, y, pixel);
}
}
return restored;
}
示例3: createDataBC
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static SurfaceData createDataBC(BufferedImage bImg,
SurfaceType sType,
int primaryBank) {
ByteComponentRaster bcRaster =
(ByteComponentRaster)bImg.getRaster();
BufImgSurfaceData bisd =
new BufImgSurfaceData(bcRaster.getDataBuffer(), bImg, sType);
ColorModel cm = bImg.getColorModel();
IndexColorModel icm = ((cm instanceof IndexColorModel)
? (IndexColorModel) cm
: null);
bisd.initRaster(bcRaster.getDataStorage(),
bcRaster.getDataOffset(primaryBank), 0,
bcRaster.getWidth(),
bcRaster.getHeight(),
bcRaster.getPixelStride(),
bcRaster.getScanlineStride(),
icm);
return bisd;
}
示例4: getPixels
import java.awt.image.BufferedImage; //导入方法依赖的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
*/
static byte[] getPixels(BufferedImage img,
int x, int y, int w, int h, byte[] pixels) {
if (w == 0 || h == 0) {
return new byte[0];
}
if (pixels == null) {
pixels = new byte[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_BYTE_GRAY) {
Raster raster = img.getRaster();
return (byte[]) raster.getDataElements(x, y, w, h, pixels);
} else {
throw new IllegalArgumentException("Only type BYTE_GRAY is supported");
}
}
示例5: createIndexedImage
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
protected static BufferedImage createIndexedImage(int w, int h,
IndexColorModel icm)
{
BufferedImage img = new BufferedImage(w, h,
BufferedImage.TYPE_BYTE_INDEXED,
icm);
int mapSize = icm.getMapSize();
int width = w / mapSize;
WritableRaster wr = img.getRaster();
for (int i = 0; i < mapSize; i++) {
for (int y = 0; y < h; y++) {
for (int x = 0; x < width; x++) {
wr.setSample(i * width + x, y, 0, i);
}
}
}
return img;
}
示例6: getIndexedImage
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
protected RenderedImage getIndexedImage() {
IndexColorModel icm = getIndexColorModel();
BufferedImage dst =
new BufferedImage(src.getWidth(), src.getHeight(),
BufferedImage.TYPE_BYTE_INDEXED, icm);
WritableRaster wr = dst.getRaster();
for (int y =0; y < dst.getHeight(); y++) {
for (int x = 0; x < dst.getWidth(); x++) {
Color aColor = getSrcColor(x,y);
wr.setSample(x, y, 0, findColorIndex(root, aColor));
}
}
return dst;
}
示例7: getChannel
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static BufferedImage getChannel(BufferedImage img, int channel) {
if(channel == 0xFFFF0000)
channel = 0;
else if(channel == 0xFF00FF00)
channel = 1;
else if(channel == 0xFF0000FF)
channel = 2;
WritableRaster r = img.getRaster();
BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
int[] nullArray = null;
img2.getRaster().setSamples(0, 0, r.getWidth(), r.getHeight(), channel, r.getSamples(0, 0, r.getWidth(), r.getHeight(), channel, nullArray));
return img2;
}
示例8: getPixeisVizinhos3x3
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static List<Integer> getPixeisVizinhos3x3(BufferedImage img, int i, int j, int tipoPixel) {
List<Integer> pixeisVizinhos = new ArrayList<>();
WritableRaster raster = img.getRaster();
int pixels[] = new int[4];
pixeisVizinhos.add(raster.getPixel(i - 1, j - 1, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i - 1, j, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i - 1, j + 1, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i, j - 1, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i, j, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i, j + 1, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i + 1, j - 1, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i + 1, j, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i + 1, j + 1, pixels)[tipoPixel]);
Collections.sort(pixeisVizinhos);
return pixeisVizinhos;
}
示例9: getPixeisVizinhos2x2
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static List<Integer> getPixeisVizinhos2x2(BufferedImage img, int i, int j, int tipoPixel) {
List<Integer> pixeisVizinhos = new ArrayList<>();
WritableRaster raster = img.getRaster();
int pixels[] = new int[4];
pixeisVizinhos.add(raster.getPixel(i - 1, j, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i, j - 1, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i, j, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i, j + 1, pixels)[tipoPixel]);
pixeisVizinhos.add(raster.getPixel(i + 1, j, pixels)[tipoPixel]);
Collections.sort(pixeisVizinhos);
return pixeisVizinhos;
}
示例10: preloadLineTile
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public void preloadLineTile(int y, int length, int band) {
TIFF tiff=(TIFF)getImage(band);
if (y < 0) {
return;
}
preloadedInterval = new int[]{y, y + length};
Rectangle rect = new Rectangle(0, y, tiff.xSize, length);
rect=tiff.getBounds().intersection(rect);
try {
BufferedImage bi=null;
try{
bi=tiff.read(0, rect);
}catch(Exception e){
logger.warn("Problem reading image POS x:"+0+ " y: "+y +" try to read again");
try {
Thread.sleep(100);
} catch(InterruptedException exx) {
Thread.currentThread().interrupt();
}
bi=tiff.read(0, rect);
}
WritableRaster raster=bi.getRaster();
preloadedData=(Short[])raster.getDataElements(0, 0, raster.getWidth(), raster.getHeight(), null);//tSamples(0, 0, raster.getWidth(), raster.getHeight(), 0, (short[]) null);
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}finally{
}
}
示例11: bufferedImage
import java.awt.image.BufferedImage; //导入方法依赖的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;
}
示例12: propertyChange
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
synchronized public void propertyChange(PropertyChangeEvent evt) {
if ((aviOutputStream != null && isWriteEnabled())
&& (evt.getPropertyName() == AEFrameChipRenderer.EVENT_NEW_FRAME_AVAILBLE)
&& !chip.getAeViewer().isPaused()) {
FloatBuffer frame = ((AEFrameChipRenderer)chip.getRenderer()).getPixmap();
BufferedImage bufferedImage = new BufferedImage(chip.getSizeX(), chip.getSizeY(), BufferedImage.TYPE_3BYTE_BGR);
WritableRaster raster = bufferedImage.getRaster();
int sx = chip.getSizeX(), sy = chip.getSizeY();
for (int y = 0; y < sy; y++) {
for (int x = 0; x < sx; x++) {
int k = renderer.getPixMapIndex(x, y);
// bufferedImage.setRGB(x, y, (int) (frame[k] * 1024));
int yy = sy - y - 1;
int r = (int) (frame.get(k) * 255); // must flip image vertially according to java convention that image starts at upper left
int g = (int) (frame.get(k+1) * 255); // must flip image vertially according to java convention that image starts at upper left
int b = (int) (frame.get(k+2) * 255); // must flip image vertially according to java convention that image starts at upper left
raster.setSample(x, yy, 0, r);
raster.setSample(x, yy, 1, g);
raster.setSample(x, yy, 2, b);
}
}
try {
aviOutputStream.writeFrame(bufferedImage);
int timestamp = renderer.getTimestampFrameEnd();
writeTimecode(timestamp);
incrementFramecountAndMaybeCloseOutput();
} catch (IOException ex) {
Logger.getLogger(DavisFrameAviWriter.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (evt.getPropertyName() == AEInputStream.EVENT_REWIND) {
doCloseFile();
}
}
示例13: isBlack
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static boolean isBlack(BufferedImage image, int x, int y) {
if (image.getType() == BufferedImage.TYPE_BYTE_BINARY) {
WritableRaster raster = image.getRaster();
int pixelRGBValue = raster.getSample(x, y, 0);
if (pixelRGBValue == 0) {
return true;
} else {
return false;
}
}
int luminanceValue = 140;
return isBlack(image, x, y, luminanceValue);
}
示例14: createImage
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private BufferedImage createImage(GeoImageReader gir, int x, int y, int width, int height) {
BufferedImage bufferedImage = new BufferedImage(width, height, gir.getType(true));
//System.out.println(zoom);
WritableRaster raster = bufferedImage.getRaster();
// Put the pixels on the raster.
//if (bands.length == 1) {
// int band = band;
nat = gir.readTile(x, y, width, height,band);
raster.setPixels(0, 0, width, height, nat);
/* } else {
int b = 0;
for (int band : bands) {
gir.setBand(band);
nat = gir.readTile(x, y, width, height);
///if (zoom == 1) {
raster.setSamples(0, 0, width, height, b, nat);
/*
* for (int h = 0; h < height; h++) {
* int temp = h * width;
* for (int w = 0; w < width; w++) {
* raster.setSample(w, h, b, nat[temp + w]);
* }
* }
**/
/*
* } else {
* for (int h = 0; h < height; h++) {
* int temp = (int) (h * zoom) * (int) (width * zoom);
* for (int w = 0; w < width; w++) {
* try {
* raster.setSample(w, h, b, nat[temp + (int) (w * zoom)]);
* } catch (Exception e) {
* }
* }
* }
* }
**/
/* b++;
if (b > raster.getNumBands()) {
break;
}
}
}*/
return bufferedImage;
}
示例15: cropMasked
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static List<File> cropMasked(BufferedImage image) throws IOException {
// now we iterate over the rows and remove the masked areas since the
// text we want to read is underneath it
WritableRaster raster = image.getRaster();
List<Integer> rowsToRemove = new ArrayList<>();
for (int yy = 0; yy < image.getHeight(); yy++) {
int masked = 0;
for (int xx = 0; xx < image.getWidth(); xx++) {
if (matchColor(getPixelValue(raster, xx, yy), Color.MAGENTA)) {
masked++;
}
}
float maskAmount = masked > 0 ? (float) masked / (float) image.getWidth() : 0;
if (maskAmount > 0.02f) {
rowsToRemove.add(yy);
}
}
List<SubImage> subImages = extractSubimageBetweenMaskedRows(rowsToRemove, image.getHeight(), 50);
List<File> result = new ArrayList<>(subImages.size() * 3);
int i = 0;
for (SubImage subImage : subImages) {
BufferedImage cut = image.getSubimage(0, subImage.y, image.getWidth(), subImage.height);
File tempFile;
tempFile = File.createTempFile("subImage_" + i + "_c1", ".png", TMP_FILE_DIR);
tempFile.deleteOnExit();
ImageIO.write(cut.getSubimage(50, 0, 200, cut.getHeight()), "png", tempFile);
result.add(tempFile);
tempFile = File.createTempFile("subImage_" + i + "_c2", ".png", TMP_FILE_DIR);
tempFile.deleteOnExit();
ImageIO.write(cut.getSubimage(255, 0, 200, cut.getHeight()), "png", tempFile);
result.add(tempFile);
tempFile = File.createTempFile("subImage_" + i + "_c3", ".png", TMP_FILE_DIR);
tempFile.deleteOnExit();
ImageIO.write(cut.getSubimage(465, 0, 200, cut.getHeight()), "png", tempFile);
result.add(tempFile);
i++;
}
return result;
}