本文整理匯總了Java中java.awt.image.Raster.getPixels方法的典型用法代碼示例。如果您正苦於以下問題:Java Raster.getPixels方法的具體用法?Java Raster.getPixels怎麽用?Java Raster.getPixels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.image.Raster
的用法示例。
在下文中一共展示了Raster.getPixels方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: grabPixels
import java.awt.image.Raster; //導入方法依賴的package包/類
/**
* Put the scanline y of the source ROI view Raster into the
* 1-line Raster for writing. This handles ROI and band
* rearrangements, and expands indexed images. Subsampling is
* done in the native code.
* This is called by the native code.
*/
private void grabPixels(int y) {
Raster sourceLine = null;
if (indexed) {
sourceLine = srcRas.createChild(sourceXOffset,
sourceYOffset+y,
sourceWidth, 1,
0, 0,
new int [] {0});
// If the image has BITMASK transparency, we need to make sure
// it gets converted to 32-bit ARGB, because the JPEG encoder
// relies upon the full 8-bit alpha channel.
boolean forceARGB =
(indexCM.getTransparency() != Transparency.OPAQUE);
BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
forceARGB);
sourceLine = temp.getRaster();
} else {
sourceLine = srcRas.createChild(sourceXOffset,
sourceYOffset+y,
sourceWidth, 1,
0, 0,
srcBands);
}
if (convertTosRGB) {
if (debug) {
System.out.println("Converting to sRGB");
}
// The first time through, converted is null, so
// a new raster is allocated. It is then reused
// on subsequent lines.
converted = convertOp.filter(sourceLine, converted);
sourceLine = converted;
}
if (isAlphaPremultiplied) {
WritableRaster wr = sourceLine.createCompatibleWritableRaster();
int[] data = null;
data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
sourceLine.getWidth(), sourceLine.getHeight(),
data);
wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
sourceLine.getWidth(), sourceLine.getHeight(),
data);
srcCM.coerceData(wr, false);
sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
wr.getWidth(), wr.getHeight(),
0, 0,
srcBands);
}
raster.setRect(sourceLine);
if ((y > 7) && (y%8 == 0)) { // Every 8 scanlines
cbLock.lock();
try {
processImageProgress((float) y / (float) sourceHeight * 100.0F);
} finally {
cbLock.unlock();
}
}
}
示例2: apply
import java.awt.image.Raster; //導入方法依賴的package包/類
@Override
public void apply(Diagram d) {
boolean logarithmic = mode.equalsIgnoreCase(LOGARITHMIC);
if (!logarithmic && !mode.equalsIgnoreCase(LINEAR)) {
throw new RuntimeException("Unknown mode: " + mode);
}
Rectangle bounds = new Rectangle(shadeCount, 1);
LinearGradientPaint lgp = new LinearGradientPaint(bounds.x, bounds.y, bounds.width, bounds.y, fractions, colors);
PaintContext context = lgp.createContext(null, bounds, bounds.getBounds2D(), AffineTransform.getTranslateInstance(0, 0), new RenderingHints(null));
Raster raster = context.getRaster(bounds.x, bounds.y, bounds.width, bounds.height);
int[] rgb = raster.getPixels(bounds.x, bounds.y, bounds.width, bounds.height, (int[]) null);
Color[] shades = new Color[rgb.length / 3];
for (int i = 0; i < shades.length; ++i) {
shades[i] = new Color(rgb[i * 3], rgb[i * 3 + 1], rgb[i * 3 + 2]);
}
List<Figure> figures = d.getFigures();
for (Figure f : figures) {
String property = f.getProperties().get(propertyName);
if (property != null) {
try {
float value = Float.parseFloat(property);
Color nodeColor;
if (value <= minValue) {
nodeColor = colors[0];
} else if (value >= maxValue) {
nodeColor = colors[colors.length - 1];
} else {
double normalized = value - minValue;
double interval = maxValue - minValue;
int index;
// Use Math.ceil() to make values above zero distinguishable from zero
if (logarithmic) {
index = (int) Math.ceil(shades.length * Math.log(1 + normalized) / Math.log(1 + interval));
} else {
index = (int) Math.ceil(shades.length * normalized / interval);
}
nodeColor = shades[index];
}
f.setColor(nodeColor);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}