Why setFromPixels

Hello Members, i am a newbie with openframeworks and have a little bit experience of c++ programming.

docu from getPixels: returns the pixels as an array of unsigned chars. NOTE: this is not a copy but the actual pixels of the ofImage.

If this is no copy, why i have to set the pixels with: setFromPixels?

Sorry, but i want to understand the reason.

struct PixelRGB {  
    unsigned char r, g, b;  
//allocates memory for the image  
Map.allocate(w, h, OF_IMAGE_COLOR);  
//get Pixel Pointer => das ist eigentlich keine Copy, warum muss ich dann wieder SetFromPixel machen?  
PixelRGB *pixels = (PixelRGB *)Map.getPixels();  
//Manipulate pixel here  
//set Pixels to the image  
Map.setFromPixels((unsigned char *)pixels, width, height, OF_IMAGE_COLOR);  

Ciao and have a nice day

getPixels() returns a pointer to the pixels of your image: this means that if you do something like:

pix = myImage.getPixels();  
for(int i=0;i<w*h;i++){  

you’ll actually fill myImage’s pixels with noise, but, if you call myImage.draw() right away, you won’t see any change in your image. This is because the drawing is handled through a texture, so you need to send your updated pixels to the GPU: you can do this calling myImage.update().

setFromPixels() is not needed, but if you use it, it will have the same effect because, after a series of checks and after rewriting the pixels array, it makes a call to update().

okay thank you, know i understand the problem.

Thx and bye