本文整理汇总了Java中java.awt.image.Raster.getPixel方法的典型用法代码示例。如果您正苦于以下问题:Java Raster.getPixel方法的具体用法?Java Raster.getPixel怎么用?Java Raster.getPixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.Raster
的用法示例。
在下文中一共展示了Raster.getPixel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: trimmedImage
import java.awt.image.Raster; //导入方法依赖的package包/类
/**
* Trims the transparent pixels from the given {@link BufferedImage} (returns a sub-image).
*
* @param source The source image.
* @return A new, trimmed image, or the source image if no trim is performed.
*/
public static BufferedImage trimmedImage(BufferedImage source) {
final int minAlpha = 1;
final int srcWidth = source.getWidth();
final int srcHeight = source.getHeight();
Raster raster = source.getRaster();
int l = srcWidth, t = srcHeight, r = 0, b = 0;
int alpha, x, y;
int[] pixel = new int[4];
for (y = 0; y < srcHeight; y++) {
for (x = 0; x < srcWidth; x++) {
raster.getPixel(x, y, pixel);
alpha = pixel[3];
if (alpha >= minAlpha) {
l = Math.min(x, l);
t = Math.min(y, t);
r = Math.max(x, r);
b = Math.max(y, b);
}
}
}
if (l > r || t > b) {
// No pixels, couldn't trim
return source;
}
return source.getSubimage(l, t, r - l + 1, b - t + 1);
}
示例2: runTest
import java.awt.image.Raster; //导入方法依赖的package包/类
public void runTest(Object context, int numReps) {
Raster ras = ((Context) context).ras;
int pixeldata[] = ((Context) context).pixeldata;
do {
ras.getPixel(numReps&7, 0, pixeldata);
} while (--numReps > 0);
}
示例3: getHorizontalRulings
import java.awt.image.Raster; //导入方法依赖的package包/类
private List<Ruling> getHorizontalRulings(BufferedImage image) {
// get all horizontal edges, which we'll define as a change in grayscale colour
// along a straight line of a certain length
ArrayList<Ruling> horizontalRulings = new ArrayList<>();
Raster r = image.getRaster();
int width = r.getWidth();
int height = r.getHeight();
for (int x = 0; x < width; x++) {
int[] lastPixel = r.getPixel(x, 0, (int[]) null);
for (int y = 1; y < height - 1; y++) {
int[] currPixel = r.getPixel(x, y, (int[]) null);
int diff = Math.abs(currPixel[0] - lastPixel[0]);
if (diff > GRAYSCALE_INTENSITY_THRESHOLD) {
// we hit what could be a line
// don't bother scanning it if we've hit a pixel in the line before
boolean alreadyChecked = false;
for (Line2D.Float line : horizontalRulings) {
if (y == line.getY1() && x >= line.getX1() && x <= line.getX2()) {
alreadyChecked = true;
break;
}
}
if (alreadyChecked) {
lastPixel = currPixel;
continue;
}
int lineX = x + 1;
while (lineX < width) {
int[] linePixel = r.getPixel(lineX, y, (int[]) null);
int[] abovePixel = r.getPixel(lineX, y - 1, (int[]) null);
if (Math.abs(linePixel[0] - abovePixel[0]) <= GRAYSCALE_INTENSITY_THRESHOLD
|| Math.abs(currPixel[0] - linePixel[0]) > GRAYSCALE_INTENSITY_THRESHOLD) {
break;
}
lineX++;
}
int endX = lineX - 1;
int lineWidth = endX - x;
if (lineWidth > HORIZONTAL_EDGE_WIDTH_MINIMUM) {
horizontalRulings.add(new Ruling(new Point2D.Float(x, y), new Point2D.Float(endX, y)));
}
}
lastPixel = currPixel;
}
}
return horizontalRulings;
}
示例4: getVerticalRulings
import java.awt.image.Raster; //导入方法依赖的package包/类
private List<Ruling> getVerticalRulings(BufferedImage image) {
// get all vertical edges, which we'll define as a change in grayscale colour
// along a straight line of a certain length
ArrayList<Ruling> verticalRulings = new ArrayList<>();
Raster r = image.getRaster();
int width = r.getWidth();
int height = r.getHeight();
for (int y = 0; y < height; y++) {
int[] lastPixel = r.getPixel(0, y, (int[]) null);
for (int x = 1; x < width - 1; x++) {
int[] currPixel = r.getPixel(x, y, (int[]) null);
int diff = Math.abs(currPixel[0] - lastPixel[0]);
if (diff > GRAYSCALE_INTENSITY_THRESHOLD) {
// we hit what could be a line
// don't bother scanning it if we've hit a pixel in the line before
boolean alreadyChecked = false;
for (Line2D.Float line : verticalRulings) {
if (x == line.getX1() && y >= line.getY1() && y <= line.getY2()) {
alreadyChecked = true;
break;
}
}
if (alreadyChecked) {
lastPixel = currPixel;
continue;
}
int lineY = y + 1;
while (lineY < height) {
int[] linePixel = r.getPixel(x, lineY, (int[]) null);
int[] leftPixel = r.getPixel(x - 1, lineY, (int[]) null);
if (Math.abs(linePixel[0] - leftPixel[0]) <= GRAYSCALE_INTENSITY_THRESHOLD
|| Math.abs(currPixel[0] - linePixel[0]) > GRAYSCALE_INTENSITY_THRESHOLD) {
break;
}
lineY++;
}
int endY = lineY - 1;
int lineLength = endY - y;
if (lineLength > VERTICAL_EDGE_HEIGHT_MINIMUM) {
verticalRulings.add(new Ruling(new Point2D.Float(x, y), new Point2D.Float(x, endY)));
}
}
lastPixel = currPixel;
}
}
return verticalRulings;
}