本文整理了Java中java.awt.image.Raster.getPixel
方法的一些代码示例,展示了Raster.getPixel
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Raster.getPixel
方法的具体详情如下:
包路径:java.awt.image.Raster
类名称:Raster
方法名:getPixel
暂无
代码示例来源:origin: graphhopper/graphhopper
private void fillDataAccessWithElevationData(Raster raster, DataAccess heights, int dataAccessWidth) {
final int height = raster.getHeight();
final int width = raster.getWidth();
int x = 0;
int y = 0;
try {
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
short val = (short) raster.getPixel(x, y, (int[]) null)[0];
if (val < -1000 || val > 12000)
val = Short.MIN_VALUE;
heights.setShort(2 * (y * dataAccessWidth + x), val);
}
}
heights.flush();
} catch (Exception ex) {
throw new RuntimeException("Problem at x:" + x + ", y:" + y, ex);
}
}
代码示例来源:origin: org.apache.poi/poi
void createRaster() {
ColorModel cm = getColorModel();
raster = cm.createCompatibleWritableRaster((int)deviceBounds.getWidth(), (int)deviceBounds.getHeight());
BufferedImage img = new BufferedImage(cm, raster, false, null);
Graphics2D graphics = img.createGraphics();
graphics.setRenderingHints(hints);
graphics.translate(-deviceBounds.getX(), -deviceBounds.getY());
graphics.transform(xform);
Raster img2 = pCtx.getRaster(0, 0, gradientSteps, 1);
int[] rgb = new int[cm.getNumComponents()];
for (int i = gradientSteps-1; i>=0; i--) {
img2.getPixel(i, 0, rgb);
Color c = new Color(rgb[0],rgb[1],rgb[2]);
if (rgb.length == 4) {
// it doesn't work to use just a color with transparency ...
graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, rgb[3]/255.0f));
}
graphics.setStroke(new BasicStroke(i+1, capStyle, joinStyle));
graphics.setColor(c);
graphics.draw(shape);
}
graphics.dispose();
}
}
代码示例来源:origin: dermotte/LIRE
private static int[][][] hsvImage(Raster r) {
int[][][] pixels = new int[r.getWidth()][r.getHeight()][3];
// quantize colors for each pixel (done in HSV color space):
int[] pixel = new int[3];
for (int x = 0; x < r.getWidth(); x++) {
for (int y = 0; y < r.getHeight(); y++) {
// converting to HSV:
int[] hsv = new int[3];
convertRgbToHsv(r.getPixel(x, y, pixel), hsv);
// quantize the actual pixel:
pixels[x][y] = hsv;
}
}
return pixels;
}
代码示例来源:origin: dermotte/LIRE
private static int[][][] hsvImage(Raster r) {
int[][][] pixels = new int[r.getWidth()][r.getHeight()][3];
// quantize colors for each pixel (done in HSV color space):
int[] pixel = new int[3];
for (int x = 0; x < r.getWidth(); x++) {
for (int y = 0; y < r.getHeight(); y++) {
// converting to HSV:
int[] hsv = new int[3];
convertRgbToHsv(r.getPixel(x, y, pixel), hsv);
// quantize the actual pixel:
pixels[x][y] = hsv;
}
}
return pixels;
}
代码示例来源:origin: dermotte/LIRE
public static FloatArray2D ImageToFloatArray2D(BufferedImage ip) {
FloatArray2D image;
Raster pixelArray = ip.getRaster();
int count = 0;
int[] rgb = new int[3];
image = new FloatArray2D(ip.getWidth(), ip.getHeight());
for (int y = 0; y < ip.getHeight(); y++) {
for (int x = 0; x < ip.getWidth(); x++) {
rgb = pixelArray.getPixel(x, y, rgb);
int b = rgb[2];
int g = rgb[1];
int r = rgb[0];
image.data[count] = 0.3f * r + 0.6f * g + 0.1f * b;
count++;
}
}
return image;
}
代码示例来源:origin: dermotte/LIRE
public static FloatArray2D ImageToFloatArray2D(BufferedImage ip) {
FloatArray2D image;
Raster pixelArray = ip.getRaster();
int count = 0;
int[] rgb = new int[3];
image = new FloatArray2D(ip.getWidth(), ip.getHeight());
for (int y = 0; y < ip.getHeight(); y++) {
for (int x = 0; x < ip.getWidth(); x++) {
rgb = pixelArray.getPixel(x, y, rgb);
int b = rgb[2];
int g = rgb[1];
int r = rgb[0];
image.data[count] = 0.3f * r + 0.6f * g + 0.1f * b;
count++;
}
}
return image;
}
代码示例来源:origin: mapsforge/mapsforge
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
int width = src.getWidth();
int height = src.getHeight();
float magnitudeRest = 1f - magnitude;
for (int x = 0; x < width; ++x) {
for (int y = 0; y < height; ++y) {
src.getPixel(x, y, srcBytes);
int shadeVal = srcBytes[0];
float add = shadeVal * magnitude;
dstIn.getPixel(x, y, inFloats);
float inV = Math.max(inFloats[0], Math.max(inFloats[1], inFloats[2]));
float vScaled = inV * magnitudeRest;
float vSum = vScaled + add;
if (inV == 0) {
outFloats[0] = vSum;
outFloats[1] = vSum;
outFloats[2] = vSum;
} else {
float factor = vSum / inV;
outFloats[0] = factor * inFloats[0];
outFloats[1] = factor * inFloats[1];
outFloats[2] = factor * inFloats[2];
}
dstOut.setPixel(x, y, outFloats);
}
}
}
};
代码示例来源:origin: stackoverflow.com
int[] pixels = raster.getPixel(xx, yy, (int[]) null);
pixels[0] = 0;
pixels[1] = 0;
代码示例来源:origin: dermotte/LIRE
@Override
public void extract(BufferedImage image) {
histogram = new double[18];
double[] directionality;
ColorConvertOp op = new ColorConvertOp(image.getColorModel().getColorSpace(),
ColorSpace.getInstance(ColorSpace.CS_GRAY),
new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY));
BufferedImage bimg = op.filter(image, null);
bimg = ImageUtils.scaleImage(bimg, MAX_IMG_HEIGHT);
Raster raster = bimg.getRaster();
int[] tmp = new int[3];
this.grayScales = new int[raster.getWidth()][raster.getHeight()];
for (int i = 0; i < raster.getWidth(); i++) {
for (int j = 0; j < raster.getHeight(); j++) {
raster.getPixel(i, j, tmp);
this.grayScales[i][j] = tmp[0];
}
}
imgWidth = bimg.getWidth();
imgHeight = bimg.getHeight();
histogram[0] = this.coarseness(bimg.getWidth(), bimg.getHeight());
histogram[1] = this.contrast();
directionality = this.directionality();
for (int i = 2; i < histogram.length; i++) {
histogram[i] = directionality[i - 2];
}
}
代码示例来源:origin: dermotte/LIRE
@Override
public void extract(BufferedImage image) {
histogram = new double[18];
double[] directionality;
ColorConvertOp op = new ColorConvertOp(image.getColorModel().getColorSpace(),
ColorSpace.getInstance(ColorSpace.CS_GRAY),
new RenderingHints(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY));
BufferedImage bimg = op.filter(image, null);
bimg = ImageUtils.scaleImage(bimg, MAX_IMG_HEIGHT);
Raster raster = bimg.getRaster();
int[] tmp = new int[3];
this.grayScales = new int[raster.getWidth()][raster.getHeight()];
for (int i = 0; i < raster.getWidth(); i++) {
for (int j = 0; j < raster.getHeight(); j++) {
raster.getPixel(i, j, tmp);
this.grayScales[i][j] = tmp[0];
}
}
imgWidth = bimg.getWidth();
imgHeight = bimg.getHeight();
histogram[0] = this.coarseness(bimg.getWidth(), bimg.getHeight());
histogram[1] = this.contrast();
directionality = this.directionality();
for (int i = 2; i < histogram.length; i++) {
histogram[i] = directionality[i - 2];
}
}
代码示例来源:origin: stackoverflow.com
pixel = src.getPixel(x, y, pixel);
代码示例来源:origin: geotools/geotools
/**
* Returns a sequence of integer values for a given location (world coordinates).
*
* @param coord World coordinates of the location to evaluate.
* @param dest An array in which to store values, or {@code null}.
* @return An array containing values.
* @throws CannotEvaluateException if the values can't be computed at the specified coordinate.
* More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation
* failed because the input point has invalid coordinates.
*/
public int[] evaluate(final Point2D coord, final int[] dest) throws CannotEvaluateException {
final Point2D pixel = gridGeometry.inverseTransform(coord);
final double fx = pixel.getX();
final double fy = pixel.getY();
if (!Double.isNaN(fx) && !Double.isNaN(fy)) {
final int x = (int) Math.round(fx);
final int y = (int) Math.round(fy);
if (image.getBounds().contains(x, y)) { // getBounds() returns a cached instance.
return image.getTile(image.XToTileX(x), image.YToTileY(y)).getPixel(x, y, dest);
}
}
throw new PointOutsideCoverageException(formatEvaluateError(coord, true));
}
代码示例来源:origin: geotools/geotools
/**
* Returns a sequence of float values for a given location (world coordinates).
*
* @param coord World coordinates of the location to evaluate.
* @param dest An array in which to store values, or {@code null}.
* @return An array containing values.
* @throws CannotEvaluateException if the values can't be computed at the specified coordinate.
* More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation
* failed because the input point has invalid coordinates.
*/
public float[] evaluate(final Point2D coord, final float[] dest)
throws CannotEvaluateException {
final Point2D pixel = gridGeometry.inverseTransform(coord);
final double fx = pixel.getX();
final double fy = pixel.getY();
if (!Double.isNaN(fx) && !Double.isNaN(fy)) {
final int x = (int) Math.round(fx);
final int y = (int) Math.round(fy);
if (image.getBounds().contains(x, y)) { // getBounds() returns a cached instance.
return image.getTile(image.XToTileX(x), image.YToTileY(y)).getPixel(x, y, dest);
}
}
throw new PointOutsideCoverageException(formatEvaluateError(coord, true));
}
代码示例来源:origin: geotools/geotools
/**
* Returns a sequence of double values for a given location (world coordinates).
*
* @param coord World coordinates of the location to evaluate.
* @param dest An array in which to store values, or {@code null}.
* @return An array containing values.
* @throws CannotEvaluateException if the values can't be computed at the specified coordinate.
* More specifically, {@link PointOutsideCoverageException} is thrown if the evaluation
* failed because the input point has invalid coordinates.
*/
public double[] evaluate(final Point2D coord, final double[] dest)
throws CannotEvaluateException {
final Point2D pixel = gridGeometry.inverseTransform(coord);
final double fx = pixel.getX();
final double fy = pixel.getY();
if (!Double.isNaN(fx) && !Double.isNaN(fy)) {
final int x = (int) Math.round(fx);
final int y = (int) Math.round(fy);
if (image.getBounds().contains(x, y)) { // getBounds() returns a cached instance.
return image.getTile(image.XToTileX(x), image.YToTileY(y)).getPixel(x, y, dest);
}
}
throw new PointOutsideCoverageException(formatEvaluateError(coord, true));
}
代码示例来源:origin: apache/pdfbox
raster.getPixel(x, y, value);
代码示例来源:origin: apache/pdfbox
raster.getPixel(x, y, value);
代码示例来源:origin: geotools/geotools
/**
* Return sample dimension (band) values as an array of integers for the given <b>grid</b>
* location. The range of valid grid coordinates can be retrieved as in this example:
*
* <pre><code>
* GridEnvelope2D gridBounds = coverage.getGridGeometry2D().getGridRange();
* </code></pre>
*
* @param coord grid (ie. pixel) coordinates
* @param dest an optionally pre-allocated array; if non-null, its length should be equal to the
* number of bands (sample dimensions)
* @return band values for the given grid (pixel) location
* @throws PointOutsideCoverageException if the supplied coords are outside the grid bounds
*/
public int[] evaluate(final GridCoordinates2D coord, final int[] dest) {
if (image.getBounds().contains(coord.x, coord.y)) {
return image.getTile(image.XToTileX(coord.x), image.YToTileY(coord.y))
.getPixel(coord.x, coord.y, dest);
}
throw new PointOutsideCoverageException(formatEvaluateError(coord, true));
}
代码示例来源:origin: geotools/geotools
/**
* Return sample dimension (band) values as an array of floats for the given <b>grid</b>
* location. The range of valid grid coordinates can be retrieved as in this example:
*
* <pre><code>
* GridEnvelope2D gridBounds = coverage.getGridGeometry2D().getGridRange();
* </code></pre>
*
* @param coord grid (ie. pixel) coordinates
* @param dest an optionally pre-allocated array; if non-null, its length should be equal to the
* number of bands (sample dimensions)
* @return band values for the given grid (pixel) location
* @throws PointOutsideCoverageException if the supplied coords are outside the grid bounds
*/
public float[] evaluate(final GridCoordinates2D coord, final float[] dest) {
if (image.getBounds().contains(coord.x, coord.y)) {
return image.getTile(image.XToTileX(coord.x), image.YToTileY(coord.y))
.getPixel(coord.x, coord.y, dest);
}
throw new PointOutsideCoverageException(formatEvaluateError(coord, true));
}
代码示例来源:origin: geotools/geotools
/**
* Return sample dimension (band) values as an array of doubles for the given <b>grid</b>
* location. The range of valid grid coordinates can be retrieved as in this example:
*
* <pre><code>
* GridEnvelope2D gridBounds = coverage.getGridGeometry2D().getGridRange();
* </code></pre>
*
* @param coord grid (ie. pixel) coordinates
* @param dest an optionally pre-allocated array; if non-null, its length should be equal to the
* number of bands (sample dimensions)
* @return band values for the given grid (pixel) location
* @throws PointOutsideCoverageException if the supplied coords are outside the grid bounds
*/
public double[] evaluate(final GridCoordinates2D coord, final double[] dest) {
if (image.getBounds().contains(coord.x, coord.y)) {
return image.getTile(image.XToTileX(coord.x), image.YToTileY(coord.y))
.getPixel(coord.x, coord.y, dest);
}
throw new PointOutsideCoverageException(formatEvaluateError(coord, true));
}
代码示例来源:origin: geotools/geotools
img.getData().getPixel(100, 100, pixel);
assertEquals(255, pixel[0]);
assertEquals(0, pixel[1]);
内容来源于网络,如有侵权,请联系作者删除!