public class PImage extends Object implements PConstants, Cloneable
PApplet.loadImage(String)
,
PApplet.imageMode(int)
,
PApplet.createImage(int, int, int)
Modifier and Type | Field and Description |
---|---|
static int |
ALPHA_MASK |
static int |
BLUE_MASK |
int |
format
Format for this image, one of RGB, ARGB or ALPHA.
|
static int |
GREEN_MASK |
int |
height
( begin auto-generated from PImage_height.xml )
The height of the image in units of pixels.
|
boolean |
loaded
Loaded pixels flag
|
PApplet |
parent
Path to parent object that will be used with save().
|
int |
pixelDensity
1 for most images, 2 for hi-dpi/retina
|
int |
pixelHeight |
int[] |
pixels
( begin auto-generated from pixels.xml )
Array containing the values for all the pixels in the display window.
|
int |
pixelWidth
Actual dimensions of pixels array, taking into account the 2x setting.
|
static int |
RED_MASK |
int |
width
( begin auto-generated from PImage_width.xml )
The width of the image in units of pixels.
|
ADD, ALPHA, ALT, AMBIENT, ARC, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BEZIER_VERTEX, BLEND, BLUR, BOTTOM, BOX, BREAK, BURN, CENTER, CHATTER, CHORD, CLAMP, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CURVE_VERTEX, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ASYNC_SAVEFRAME, DISABLE_BUFFER_READING, DISABLE_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_KEY_REPEAT, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_OPTIMIZED_STROKE, DISABLE_STROKE_PERSPECTIVE, DISABLE_STROKE_PURE, DISABLE_TEXTURE_MIPMAPS, DODGE, DOWN, DXF, ELLIPSE, ENABLE_ASYNC_SAVEFRAME, ENABLE_BUFFER_READING, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_KEY_REPEAT, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_OPTIMIZED_STROKE, ENABLE_STROKE_PERSPECTIVE, ENABLE_STROKE_PURE, ENABLE_TEXTURE_MIPMAPS, ENTER, EPSILON, ERODE, ESC, EXCLUSION, FX2D, GIF, GRAY, GROUP, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LANDSCAPE, LEFT, LIGHTEST, LINE, LINE_LOOP, LINE_STRIP, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MODELVIEW, MOVE, MULTIPLY, NORMAL, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, PIE, platformNames, POINT, POINTS, POLYGON, PORTRAIT, POSTERIZE, PROBLEM, PROJECT, PROJECTION, QUAD, QUAD_BEZIER_VERTEX, QUAD_STRIP, QUADRATIC_VERTEX, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RECT, REPEAT, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPAN, SPHERE, SPOT, SQUARE, SUBTRACT, SVG, TAB, TARGA, TAU, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, VERTEX, WAIT, WHITESPACE, WINDOWS, X, Y, Z
Constructor and Description |
---|
PImage()
( begin auto-generated from PImage.xml )
Datatype for storing images.
|
PImage(Image img)
Construct a new PImage from a java.awt.Image.
|
PImage(int width,
int height) |
PImage(int width,
int height,
int format) |
PImage(int width,
int height,
int format,
int factor) |
Modifier and Type | Method and Description |
---|---|
void |
blend(int sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh,
int mode) |
void |
blend(PImage src,
int sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh,
int mode)
( begin auto-generated from PImage_blend.xml )
Blends a region of pixels into the image specified by the img
parameter.
|
static int |
blendColor(int c1,
int c2,
int mode)
( begin auto-generated from blendColor.xml )
Blends two color values together based on the blending mode given as the
MODE parameter.
|
Object |
clone()
Duplicate an image, returns new PImage object.
|
PImage |
copy() |
void |
copy(int sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh)
( begin auto-generated from PImage_copy.xml )
Copies a region of pixels from one image into another.
|
void |
copy(PImage src,
int sx,
int sy,
int sw,
int sh,
int dx,
int dy,
int dw,
int dh) |
void |
filter(int kind) |
void |
filter(int kind,
float param)
( begin auto-generated from PImage_filter.xml )
Filters an image as defined by one of the following modes:
THRESHOLD - converts the image to black and white pixels depending if they are above or below the threshold defined by the level parameter. |
PImage |
get()
Returns a copy of this PImage.
|
int |
get(int x,
int y)
( begin auto-generated from PImage_get.xml )
Reads the color of any pixel or grabs a section of an image.
|
PImage |
get(int x,
int y,
int w,
int h) |
Image |
getImage()
Use the getNative() method instead, which allows library interfaces to be
written in a cross-platform fashion for desktop, Android, and others.
|
int |
getModifiedX1() |
int |
getModifiedX2() |
int |
getModifiedY1() |
int |
getModifiedY2() |
Object |
getNative()
Returns a native BufferedImage from this PImage.
|
void |
init(int width,
int height,
int format)
Do not remove, see notes in the other variant.
|
void |
init(int width,
int height,
int format,
int factor)
Function to be used by subclasses of PImage to init later than
at the constructor, or re-init later when things changes.
|
boolean |
isLoaded() |
boolean |
isModified() |
void |
loadPixels()
( begin auto-generated from PImage_loadPixels.xml )
Loads the pixel data for the image into its pixels[] array.
|
void |
mask(int[] maskArray) |
void |
mask(PImage img)
( begin auto-generated from PImage_mask.xml )
Masks part of an image from displaying by loading another image and
using it as an alpha channel.
|
void |
resize(int w,
int h)
( begin auto-generated from PImage_resize.xml )
Resize the image to a new width and height.
|
boolean |
save(String filename)
( begin auto-generated from PImage_save.xml )
Saves the image into a file.
|
void |
set(int x,
int y,
int c)
( begin auto-generated from PImage_set.xml )
Changes the color of any pixel or writes an image directly into the
display window.
The x and y parameters specify the pixel to change and the color parameter specifies the color value. |
void |
set(int x,
int y,
PImage img)
Advanced
|
void |
setLoaded() |
void |
setLoaded(boolean l) |
void |
setModified() |
void |
setModified(boolean m) |
void |
updatePixels() |
void |
updatePixels(int x,
int y,
int w,
int h)
( begin auto-generated from PImage_updatePixels.xml )
Updates the image with the data in its pixels[] array.
|
public int format
public int[] pixels
public int pixelDensity
public int pixelWidth
public int pixelHeight
public int width
public int height
public PApplet parent
public boolean loaded
public static final int ALPHA_MASK
public static final int RED_MASK
public static final int GREEN_MASK
public static final int BLUE_MASK
public PImage()
PApplet.loadImage(String, String)
,
PApplet.imageMode(int)
,
PApplet.createImage(int, int, int)
public PImage(int width, int height)
width
- image widthheight
- image heightpublic PImage(int width, int height, int format)
format
- Either RGB, ARGB, ALPHA (grayscale alpha channel)public PImage(int width, int height, int format, int factor)
public PImage(Image img)
img
- assumes a MediaTracker has been used to fully download
the data and the img is validpublic void init(int width, int height, int format)
public void init(int width, int height, int format, int factor)
public Image getImage()
public Object getNative()
public boolean isModified()
public void setModified()
public void setModified(boolean m)
public int getModifiedX1()
public int getModifiedX2()
public int getModifiedY1()
public int getModifiedY2()
public void loadPixels()
public void updatePixels()
public void updatePixels(int x, int y, int w, int h)
x
- x-coordinate of the upper-left cornery
- y-coordinate of the upper-left cornerw
- widthh
- heightpublic Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public void resize(int w, int h)
w
- the resized image widthh
- the resized image heightget(int, int, int, int)
public boolean isLoaded()
public void setLoaded()
public void setLoaded(boolean l)
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.
x
- x-coordinate of the pixely
- y-coordinate of the pixelPApplet.set(int, int, int)
,
PApplet.pixels
,
PApplet.copy(PImage, int, int, int, int, int, int, int, int)
public PImage get(int x, int y, int w, int h)
w
- width of pixel rectangle to geth
- height of pixel rectangle to getpublic PImage get()
public PImage copy()
public void set(int x, int y, int c)
x
- x-coordinate of the pixely
- y-coordinate of the pixelc
- any value of the color datatypeget(int, int, int, int)
,
pixels
,
copy(PImage, int, int, int, int, int, int, int, int)
public void set(int x, int y, PImage img)
img
- image to copy into the original imagepublic void mask(int[] maskArray)
maskArray
- array of integers used as the alpha channel, needs to be
the same length as the image's pixel array.public void mask(PImage img)
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" grayscale by performing a proper luminance-based conversion.
img
- image to use as the maskpublic void filter(int kind)
public void filter(int kind, float param)
kind
- Either THRESHOLD, GRAY, OPAQUE, INVERT, POSTERIZE, BLUR, ERODE, or DILATEparam
- unique for each, see abovepublic void copy(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
sx
- X coordinate of the source's upper left cornersy
- Y coordinate of the source's upper left cornersw
- source image widthsh
- source image heightdx
- X coordinate of the destination's upper left cornerdy
- Y coordinate of the destination's upper left cornerdw
- destination image widthdh
- destination image heightPGraphics.alpha(int)
,
blend(PImage, int, int, int, int, int, int, int, int, int)
public void copy(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh)
src
- an image variable referring to the source image.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.
c1
- the first color to blendc2
- the second color to blendmode
- either BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, or BURNblend(PImage, int, int, int, int, int, int, int, int, int)
,
PApplet.color(float, float, float, float)
public void blend(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mode)
public void blend(PImage src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mode)
src
- an image variable referring to the source imagesx
- X coordinate of the source's upper left cornersy
- Y coordinate of the source's upper left cornersw
- source image widthsh
- source image heightdx
- X coordinate of the destinations's upper left cornerdy
- Y coordinate of the destinations's upper left cornerdw
- destination image widthdh
- destination image heightmode
- Either BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURNPApplet.alpha(int)
,
copy(PImage, int, int, int, int, int, int, int, int)
,
blendColor(int,int,int)
public boolean save(String filename)
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.
filename
- a sequence of letters and numbers