ofDoc > graphics > ofPixels

ofPixelsfile

ofPixels is an object for working with blocks of pixels, those pixels can be copied from an image that you've loaded, something that you've drawn using ofGraphics, or a ofVideoGrabber instance.

You can create an image from pixels, using on ofPixels object like so:

ofLoadImage(p, "pathToImage.jpg");

ofPixels represents pixels data on the CPU as opposed to an ofTexture which represents pixel data on the GPU. They can easily be made inter- operational though:

// do some stuff with tex
tex.readToPixels(pix); // now all the pixels from tex are in pix

You can access the pixels in an ofPixels object with the [] operator.

// put some stuff in the pixels
int i = 0;
while( i < pix.size()) {
char c = pix[i];
i++;
}

You can think of the ofPixels as the CPU side representation of pixel data that can be sent to the GPU as an ofTexture object. To draw pixels, you need to put them into an ofTexture and to manipulate an ofTextures pixel data you need an ofPixels object.

Enums

Typedefs

ofPixels typedef
ofFloatPixels typedef
ofShortPixels typedef
ofPixelsRef typedef

ofPixels_class

template<typename PixelType>
class ofPixels_< PixelType >

A class representing a collection of pixels.

Construction And Allocation

clear ()

Set Pixel Data

set ()
swap ()

Modify Existing Data

crop ()
cropTo ()
mirror ()
resize ()
swapRgb ()

Pixels Access

getData ()
getPixels () Use getData instead
() Accessing pixels as unsigned char*, instead use ofPixels or getPixels().getData() if you are really trying to access the raw data

Getters

size ()

Setters

Iterator

iterator typedef
const_iterator typedef
begin ()
end ()
begin ()
end ()
rbegin ()
rbegin ()
rend ()