|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectprocessing.core.PImage
processing.core.PGraphics
processing.core.PGraphicsJava2D
public class PGraphicsJava2D
Subclass for PGraphics that implements the graphics API using Java2D.
Pixel operations too slow? As of release 0085 (the first beta), the default renderer uses Java2D. It's more accurate than the renderer used in alpha releases of Processing (it handles stroke caps and joins, and has better polygon tessellation), but it's super slow for handling pixels. At least until we get a chance to get the old 2D renderer (now called P2D) working in a similar fashion, you can use size(w, h, P3D) instead of size(w, h) which will be faster for general pixel flipping madness.
To get access to the Java 2D "Graphics2D" object for the default renderer, use:
Graphics2D g2 = ((PGraphicsJava2D)g).g2;This will let you do Java 2D stuff directly, but is not supported in any way shape or form. Which just means "have fun, but don't complain if it breaks."
| Field Summary | |
|---|---|
boolean |
fillGradient
|
java.awt.Paint |
fillGradientObject
|
java.awt.Graphics2D |
g2
|
boolean |
strokeGradient
|
java.awt.Paint |
strokeGradientObject
|
| Fields inherited from class processing.core.PImage |
|---|
cache, format, height, imageMode, modified, mx1, mx2, my1, my2, parent, pixels, smooth, width |
| Constructor Summary | |
|---|---|
PGraphicsJava2D(int iwidth,
int iheight,
PApplet parent)
Constructor for the PGraphics object. |
|
| Method Summary | |
|---|---|
void |
applyMatrix(float n00,
float n01,
float n02,
float n10,
float n11,
float n12)
Apply a 3x2 affine transformation matrix. |
void |
background(PImage image)
Takes an RGB or ARGB image and sets it as the background. |
void |
beginDraw()
Prepares the PGraphics for drawing. |
void |
beginRaw(PGraphics recorderRaw)
|
void |
beginShape(int kind)
Start a new shape. |
void |
bezierDetail(int detail)
Ignored (not needed) in Java 2D. |
void |
bezierVertex(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
|
void |
blend(int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
Blends one area of this image to another area. |
void |
blend(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
Copies area of one image into another PImage object. |
void |
breakShape()
This feature is in testing, do not use or rely upon its implementation |
void |
clear()
Clear the pixel buffer. |
void |
copy(int sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh)
Copy things from one area of this image to another area in the same image. |
void |
copy(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2)
Copies area of one image into another PImage object. |
void |
curveDetail(int detail)
Ignored (not needed) in Java 2D. |
void |
curveVertex(float x,
float y)
See notes with the curve() function. |
void |
endDraw()
This will finalize rendering so that it can be shown on-screen. |
void |
endRaw()
|
void |
endShape(int mode)
|
void |
filter(int kind)
Method to apply a variety of basic filters to this image. |
void |
filter(int kind,
float param)
Method to apply a variety of basic filters to this image. |
PImage |
get()
Grab a copy of the current pixel buffer. |
int |
get(int x,
int y)
Returns an ARGB "color" type (a packed 32 bit int with the color. |
PImage |
get(int x,
int y,
int w,
int h)
Grab a subsection of a PImage, and copy it into a fresh PImage. |
void |
line(float x1,
float y1,
float x2,
float y2)
|
void |
loadMatrix()
Loads the current matrix into m00, m01 etc (or modelview and projection when using 3D) so that the values can be read. |
void |
loadPixels()
Call this when you want to mess with the pixels[] array. |
void |
mask(int[] alpha)
Use with caution on PGraphics. |
void |
mask(PImage alpha)
Use with caution on PGraphics. |
void |
noSmooth()
Disable smoothing. |
void |
point(float x,
float y)
End a path. |
void |
popMatrix()
|
void |
pushMatrix()
|
void |
quad(float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
float x4,
float y4)
|
void |
resetMatrix()
Load identity as the transform/model matrix. |
void |
resize(int iwidth,
int iheight)
Called in response to a resize event, handles setting the new width and height internally, as well as re-allocating the pixel buffer for the new size. |
void |
rotate(float angle)
Two dimensional rotation. |
void |
save(java.lang.String filename)
Save this image to disk. |
void |
scale(float s)
|
void |
scale(float sx,
float sy)
|
float |
screenX(float x,
float y)
Given an x and y coordinate, returns the x position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations. |
float |
screenY(float x,
float y)
Given an x and y coordinate, returns the y position of where that point would be placed on screen, once affected by translate(), scale(), or any other transformations. |
void |
set(int x,
int y,
int argb)
Silently ignores if the coordinate is outside the image. |
void |
smooth()
If true in PImage, use bilinear interpolation for copy() operations. |
void |
strokeCap(int cap)
|
void |
strokeJoin(int join)
|
void |
strokeWeight(float weight)
|
float |
textAscent()
Returns the ascent of the current font at the current size. |
float |
textDescent()
Returns the descent of the current font at the current size. |
void |
textSize(float size)
Same as parent, but override for native version of the font. |
void |
texture(PImage image)
Set texture image for current shape. |
void |
textureMode(int mode)
Set texture mode to either to use coordinates based on the IMAGE (more intuitive for new users) or NORMALIZED (better for advanced chaps) |
void |
translate(float tx,
float ty)
|
void |
triangle(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
|
void |
updatePixels()
Update the pixels[] buffer to the PGraphics image. |
void |
updatePixels(int x,
int y,
int c,
int d)
Update the pixels[] buffer to the PGraphics image. |
void |
vertex(float x,
float y)
|
void |
vertex(float x,
float y,
float z)
|
void |
vertex(float x,
float y,
float u,
float v)
|
void |
vertex(float x,
float y,
float z,
float u,
float v)
|
| Methods inherited from class processing.core.PImage |
|---|
blendColor, clone, imageMode, init, set |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public java.awt.Graphics2D g2
public boolean fillGradient
public java.awt.Paint fillGradientObject
public boolean strokeGradient
public java.awt.Paint strokeGradientObject
| Constructor Detail |
|---|
public PGraphicsJava2D(int iwidth,
int iheight,
PApplet parent)
iwidth - viewport widthiheight - viewport height| Method Detail |
|---|
public void resize(int iwidth,
int iheight)
resize in class PGraphicspublic void beginDraw()
PGraphics
beginDraw in class PGraphicspublic void endDraw()
PGraphics
endDraw in class PGraphicspublic void beginShape(int kind)
PGraphicsDifferences between beginShape() and line() and point() methods.
beginShape() is intended to be more flexible at the expense of being a little more complicated to use. it handles more complicated shapes that can consist of many connected lines (so you get joins) or lines mixed with curves.
The line() and point() command are for the far more common cases (particularly for our audience) that simply need to draw a line or a point on the screen.
From the code side of things, line() may or may not call beginShape() to do the drawing. In the beta code, they do, but in the alpha code, they did not. they might be implemented one way or the other depending on tradeoffs of runtime efficiency vs. implementation efficiency &mdash meaning the speed that things run at vs. the speed it takes me to write the code and maintain it. for beta, the latter is most important so that's how things are implemented.
beginShape in class PGraphicspublic void textureMode(int mode)
PGraphics
textureMode in class PGraphicspublic void texture(PImage image)
PGraphics
texture in class PGraphicsimage - reference to a PImage object
public void vertex(float x,
float y)
vertex in class PGraphics
public void vertex(float x,
float y,
float u,
float v)
vertex in class PGraphics
public void vertex(float x,
float y,
float z)
vertex in class PGraphics
public void vertex(float x,
float y,
float z,
float u,
float v)
vertex in class PGraphics
public void bezierVertex(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
bezierVertex in class PGraphics
public void curveVertex(float x,
float y)
PGraphics
curveVertex in class PGraphicspublic void breakShape()
PGraphics
breakShape in class PGraphicspublic void endShape(int mode)
endShape in class PGraphics
public void point(float x,
float y)
PGraphics
point in class PGraphics
public void line(float x1,
float y1,
float x2,
float y2)
line in class PGraphics
public void triangle(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
triangle in class PGraphics
public void quad(float x1,
float y1,
float x2,
float y2,
float x3,
float y3,
float x4,
float y4)
quad in class PGraphicspublic void bezierDetail(int detail)
bezierDetail in class PGraphicspublic void curveDetail(int detail)
curveDetail in class PGraphicspublic float textAscent()
PGraphics
textAscent in class PGraphicspublic float textDescent()
PGraphics
textDescent in class PGraphicspublic void textSize(float size)
textSize in class PGraphics
public void translate(float tx,
float ty)
translate in class PGraphicspublic void rotate(float angle)
PGraphics
rotate in class PGraphicspublic void scale(float s)
scale in class PGraphics
public void scale(float sx,
float sy)
scale in class PGraphicspublic void pushMatrix()
pushMatrix in class PGraphicspublic void popMatrix()
popMatrix in class PGraphicspublic void resetMatrix()
PGraphics
resetMatrix in class PGraphics
public void applyMatrix(float n00,
float n01,
float n02,
float n10,
float n11,
float n12)
PGraphics
applyMatrix in class PGraphicspublic void loadMatrix()
PGraphics
loadMatrix in class PGraphics
public float screenX(float x,
float y)
PGraphics
screenX in class PGraphics
public float screenY(float x,
float y)
PGraphics
screenY in class PGraphicspublic void strokeWeight(float weight)
strokeWeight in class PGraphicspublic void strokeJoin(int join)
strokeJoin in class PGraphicspublic void strokeCap(int cap)
strokeCap in class PGraphicspublic void background(PImage image)
PGraphicsNote that even if the image is set as RGB, the high 8 bits of each pixel should be set opaque (0xFF000000), because the image data will be copied directly to the screen, and non-opaque background images may have strange behavior. Using image.filter(OPAQUE) will handle this easily.
When using 3D, this will also clear out the zbuffer and stencil buffer if they exist.
background in class PGraphicspublic void clear()
PGraphics
public void smooth()
PImage
smooth in class PImagepublic void noSmooth()
PImage
noSmooth in class PImagepublic void beginRaw(PGraphics recorderRaw)
beginRaw in class PGraphicspublic void endRaw()
endRaw in class PGraphicspublic void loadPixels()
PImage
loadPixels in class PImagepublic void updatePixels()
Unlike in PImage, where updatePixels() only requests that the update happens, in PGraphicsJava2D, this will happen immediately.
updatePixels in class PImage
public void updatePixels(int x,
int y,
int c,
int d)
Unlike in PImage, where updatePixels() only requests that the update happens, in PGraphicsJava2D, this will happen immediately.
updatePixels in class PImage
public int get(int x,
int y)
PImageIf the image is in RGB format (i.e. on a PVideo object), the value will get its high bits set, just to avoid cases where they haven't been set already.
If the image is in ALPHA format, this returns a white with its alpha value set.
This function is included primarily for beginners. It is quite slow because it has to check to see if the x, y that was provided is inside the bounds, and then has to check to see what image type it is. If you want things to be more efficient, access the pixels[] array directly.
get in class PImage
public PImage get(int x,
int y,
int w,
int h)
PImage
get in class PImagepublic PImage get()
get in class PImage
public void set(int x,
int y,
int argb)
PImage
set in class PImagepublic void mask(int[] alpha)
PGraphics
mask in class PGraphicspublic void mask(PImage alpha)
PGraphics
mask in class PGraphicspublic void filter(int kind)
PImage
filter in class PImage
public void filter(int kind,
float param)
PImage
filter in class PImage
public void copy(int sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh)
PImage
copy in class PImage
public void copy(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2)
PImage
copy in class PImage
public void blend(int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
PImage
blend in class PImagePImage.blendColor(int,int,int)
public void blend(PImage src,
int sx1,
int sy1,
int sx2,
int sy2,
int dx1,
int dy1,
int dx2,
int dy2,
int mode)
PImage
blend in class PImagePImage.blendColor(int,int,int)public void save(java.lang.String filename)
PImageAs of revision 0100, this function requires an absolute path, in order to avoid confusion. To save inside the sketch folder, use the function savePath() from PApplet, or use saveFrame() instead. As of revision 0116, savePath() is not needed if this object has been created (as recommended) via createImage() or createGraphics() or one of its neighbors.
As of revision 0115, when using Java 1.4 and later, you can write
to several formats besides tga and tiff. If Java 1.4 is installed
and the extension used is supported (usually png, jpg, jpeg, bmp,
and tiff), then those methods will be used to write the image.
To get a list of the supported formats for writing, use:
println(javax.imageio.ImageIO.getReaderFormatNames())
To use the original built-in image writers, use .tga or .tif as the extension, or don't include an extension. When no extension is used, the extension .tif will be added to the file name.
The ImageIO API claims to support wbmp files, however they probably require a black and white image. Basic testing produced a zero-length file with no error.
save in class PImage
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||