Hi!
My name is Steve. I’m new to programming and of. My first impressions are overwhelming! Thanks to everyone, who has contributed to this wonderful programming framework!
Everything worked smoothly so far. No, however, I am facing my first problem:
I work on Win 10, with VS 2017. I want to access raw pixel data, via ofPixels. Changes on raw data, however, don’t seem to effect the corresponding ofImage object. See the code as an example. It should set the red channel on all pixels to maximum. In the draw() - Function the image is outputed beside the original. They are the same. What didn’t I consider.
in ofApp.h:
ofImage image;
ofImage imageOrg;
in ofApp.cpp:
void ofApp::setup(){
image.loadImage("sunflower2.png");
imageOrg.loadImage("sunflower2.png");
int components; // number of color components
int type = image.getImageType();
if (type == OF_IMAGE_COLOR) {
components = 3;
}
if (type == OF_IMAGE_COLOR_ALPHA) {
components = 4;
}
ofPixels data = image.getPixels();
for (int y = 0; y < image.getWidth(); y++) {
for (int x = 0; x < image.getHeight(); x++) {
int i = components * (y * image.getWidth() + x);
data[i] = 255; // set red-value to maximum
}
}
image.update();
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
//Set up white background
ofBackground(255, 255, 255);
ofSetColor(255);
imageOrg.draw(0, 0);
image.draw(400, 0);
}
Thanks for any help!
Steve