本文整理匯總了Java中processing.core.PGraphics.loadPixels方法的典型用法代碼示例。如果您正苦於以下問題:Java PGraphics.loadPixels方法的具體用法?Java PGraphics.loadPixels怎麽用?Java PGraphics.loadPixels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類processing.core.PGraphics
的用法示例。
在下文中一共展示了PGraphics.loadPixels方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createBufferedImage
import processing.core.PGraphics; //導入方法依賴的package包/類
public BufferedImage createBufferedImage(){
PGraphics pg = papplet.g;
// BufferedImage img_native = (BufferedImage) papplet.getGraphics().getNative();
// System.out.println(pg.format == PConstants.ARGB);
// System.out.println( img_native.getType() == BufferedImage.TYPE_INT_ARGB);
pg.loadPixels();
BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_RGB);
WritableRaster wr = img.getRaster();
wr.setDataElements(0, 0, pg.width, pg.height, pg.pixels);
return img;
}
示例2: drawLayer
import processing.core.PGraphics; //導入方法依賴的package包/類
private void drawLayer(PGraphics pg, int m){
int tileoffsetx, tileoffsety, n, dif;
float x = 0, y = 0;
Layer l = this.layer[m];
switch(l.type){
case "layer":
map.drawTileLayer(pg, m);
break;
case "imagelayer":
pg.image(l.image, -this.camleft + l.offsetx, -this.camtop + l.offsety);
break;
case "objectgroup":
pg.fill(l.objcolor);pg.stroke(l.objcolor); pg.strokeWeight(1);
for(StringDict o: l.objects){
if(!o.hasKey("visible")){
pg.pushMatrix();
pg.resetMatrix();
pg.pushStyle();
pg.ellipseMode(parent.CORNER);
pg.translate(parent.parseFloat(o.get("x")) - l.offsetx - this.camleft, parent.parseFloat(o.get("y"))- l.offsety - this.camtop);
if(o.hasKey("rotation")) pg.rotate(parent.parseFloat(o.get("rotation")) * parent.PI / 180);
switch(o.get("object")){
case "rectangle":
pg.rect(0, 0, parent.parseFloat(o.get("width")), parent.parseFloat(o.get("height")));
break;
case "ellipse":
pg.ellipse(0, 0, parent.parseFloat(o.get("width")), parent.parseFloat(o.get("height")));
break;
case "tile":
if(o.hasKey("rotation")) pg.rotate(-parent.parseFloat(o.get("rotation")) * parent.PI / 180);
pg.translate(0, -this.tile[parent.parseInt(o.get("gid")) - 1].image.height);
if(o.hasKey("rotation")) pg.rotate(parent.parseFloat(o.get("rotation")) * parent.PI / 180);
pg.image(this.tile[parent.parseInt(o.get("gid")) - 1].image, this.tile[parent.parseInt(o.get("gid")) - 1].offsetx, this.tile[parent.parseInt(o.get("gid")) - 1].offsety, parent.parseFloat(o.get("width")), parent.parseFloat(o.get("height")));
break;
case "polygon":
case "polyline":
if(o.get("object").equals("polyline")) pg.noFill();
pg.beginShape();
for(String s: parent.split(o.get("points"), " ")){
float [] p = parent.parseFloat(parent.split(s, ","));
pg.vertex(p[0], p[1]);
}
if(o.get("object").equals("polyline")) pg.endShape(); else pg.endShape(parent.CLOSE);
break;
}
pg.popStyle();
pg.popMatrix();
}
}
break;
}
if(pg != parent.g && l.opacity < 1){//applyOpacity
pg.loadPixels();
int a = parent.parseInt(parent.map(l.opacity, 0, 1, 1, 255));
for (int p = 0; p < pg.pixels.length; p++) if(parent.alpha(pg.pixels[p]) > a) pg.pixels[p] = parent.color(parent.red(pg.pixels[p]), parent.green(pg.pixels[p]), parent.blue(pg.pixels[p]), a);
pg.updatePixels();
}
}
示例3: apply
import processing.core.PGraphics; //導入方法依賴的package包/類
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
List<Object> params = ProcessingUtil.parseParams(stack, 0);
PGraphics pg = (PGraphics) params.get(0);
pg.loadPixels();
List<Long> pixels = new ArrayList<Long>();
for (int pixel: pg.pixels) {
pixels.add((long) pixel);
}
stack.push(pg);
stack.push(pixels);
return stack;
}
示例4: apply
import processing.core.PGraphics; //導入方法依賴的package包/類
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
List<Object> params = ProcessingUtil.parseParams(stack, 1);
PGraphics pg = (PGraphics) params.get(0);
if (!(params.get(1) instanceof List)) {
throw new WarpScriptException(getName() + " expects an array of pixels on top of the stack.");
}
List<Object> pixels = (List<Object>) params.get(1);
pg.loadPixels();
if (pixels.size() != pg.pixels.length) {
throw new WarpScriptException(getName() + " expected an array of " + pg.pixels.length + " pixels, found " + pixels.size());
}
for (int i = 0; i < pg.pixels.length; i++) {
if (!(pixels.get(i) instanceof Long)) {
throw new WarpScriptException(getName() + " expected an array of LONG.");
}
pg.pixels[i] = ((Long) pixels.get(i)).intValue();
}
pg.updatePixels();
stack.push(pg);
return stack;
}