|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object processing.core.PImage
public class PImage
Storage class for pixel data. This is the base class for most image and pixel information, such as PGraphics and the video library classes.
Code for copying, resizing, scaling, and blending contributed by toxi.
Field Summary | |
---|---|
int |
format
Format for this image, one of RGB, ARGB or ALPHA. |
int |
height
|
PApplet |
parent
Path to parent object that will be used with save(). |
int[] |
pixels
|
int |
width
|
Constructor Summary | |
---|---|
PImage()
Create an empty image object, set its format to RGB. |
|
PImage(java.awt.Image img)
Construct a new PImage from a java.awt.Image. |
|
PImage(int width,
int height)
Create a new RGB (alpha ignored) image of a specific size. |
|
PImage(int width,
int height,
int format)
|
Method Summary | |
---|---|
void |
blend(int sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh,
int mode)
Blends one area of this image to another area. |
void |
blend(PImage src,
int sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh,
int mode)
Copies area of one image into another PImage object. |
static int |
blendColor(int c1,
int c2,
int mode)
Blend two colors based on a particular mode. |
java.lang.Object |
clone()
Duplicate an image, returns new PImage object. |
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 sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh)
Copies area of one image into another PImage object. |
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()
Returns a copy of this PImage. |
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. |
java.lang.Object |
getCache(java.lang.Object parent)
Get cache storage data for the specified renderer. |
java.awt.Image |
getImage()
Returns a BufferedImage from this PImage. |
void |
init(int width,
int height,
int format)
Function to be used by subclasses of PImage to init later than at the constructor, or re-init later when things changes. |
boolean |
isModified()
|
void |
loadPixels()
Call this when you want to mess with the pixels[] array. |
void |
mask(int[] alpha)
Set alpha channel for an image. |
void |
mask(PImage alpha)
Set alpha channel for an image using another image as the source. |
void |
removeCache(java.lang.Object parent)
Remove information associated with this renderer from the cache, if any. |
void |
resize(int wide,
int high)
Resize this image to a new width and height. |
void |
save(java.lang.String path)
Save this image to disk. |
void |
set(int x,
int y,
int c)
Set a single pixel to the specified color. |
void |
set(int x,
int y,
PImage src)
Efficient method of drawing an image's pixels directly to this surface. |
void |
setCache(java.lang.Object parent,
java.lang.Object storage)
Store data of some kind for a renderer that requires extra metadata of some kind. |
void |
setModified()
|
void |
setModified(boolean m)
|
void |
updatePixels()
Call this when finished messing with the pixels[] array. |
void |
updatePixels(int x,
int y,
int w,
int h)
Mark the pixels in this region as needing an update. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public int format
public int[] pixels
public int width
public int height
public PApplet parent
Constructor Detail |
---|
public PImage()
public PImage(int width, int height)
public PImage(int width, int height, int format)
public PImage(java.awt.Image img)
Method Detail |
---|
public void init(int width, int height, int format)
public java.awt.Image getImage()
public void setCache(java.lang.Object parent, java.lang.Object storage)
public java.lang.Object getCache(java.lang.Object parent)
parent
- The PGraphics object (or any object, really) associated
public void removeCache(java.lang.Object parent)
parent
- The PGraphics object whose cache data should be removedpublic boolean isModified()
public void setModified()
public void setModified(boolean m)
public void loadPixels()
public void updatePixels()
public void updatePixels(int x, int y, int w, int h)
This is not currently used by any of the renderers, however the api is structured this way in the hope of being able to use this to speed things up in the future.
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public void resize(int wide, int high)
public int get(int x, int y)
If 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.
public PImage get(int x, int y, int w, int h)
public PImage get()
public void set(int x, int y, int c)
public void set(int x, int y, PImage src)
public void mask(int[] alpha)
Strictly speaking the "blue" value from the source image is used as the alpha color. For a fully grayscale image, this is correct, but for a color image it's not 100% accurate. For a more accurate conversion, first use filter(GRAY) which will make the image into a "correct" grayscake by performing a proper luminance-based conversion.
public void mask(PImage alpha)
public void filter(int kind)
public void filter(int kind, float param)
public void copy(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
public void copy(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
public static int blendColor(int c1, int c2, int mode)
A useful reference for blending modes and their algorithms can be found in the SVG specification.
It is important to note that Processing uses "fast" code, not necessarily "correct" code. No biggie, most software does. A nitpicker can find numerous "off by 1 division" problems in the blend code where >>8 or >>7 is used when strictly speaking /255.0 or /127.0 should have been used.
For instance, exclusion (not intended for real-time use) reads r1 + r2 - ((2 * r1 * r2) / 255) because 255 == 1.0 not 256 == 1.0. In other words, (255*255)>>8 is not the same as (255*255)/255. But for real-time use the shifts are preferrable, and the difference is insignificant for applications built with Processing.
public void blend(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mode)
blendColor(int,int,int)
public void blend(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mode)
blendColor(int,int,int)
public void save(java.lang.String path)
As 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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |