擦除图像部分以使像素透明

时间:2013-07-15 06:26:56

标签: c++ c++11 openframeworks

我在 openFrameworks 中工作,这是一组C ++库。

我想要做的就是当一个形状(橡皮擦)经过适当的像素时,简单地'擦除'ofImage的某些像素(一个加载/显示图像的类,并且可以访问它的像素数组)图像。非常简单的东西 - 我想 - 但我有精神障碍!

ofImage有两种方法 - getPixels()getPixelsRef()似乎接近我想要做的事情,但我使用的方法并不能完全给我我想要的结果。

以下是尝试从背景图像的像素更新前景图像的像素的示例:

ofPixelsRef fore = foreground.getPixelsRef();
ofPixelsRef back = background.getPixelsRef();

for(int x = 0; x < foreground.getWidth()/2; x++) {
    for (int y = 0; y < foreground.getHeight(); y++) {
        ofColor c = back.getColor(x, y);
        fore.setColor(x, y, c);
    }
}

foreground.setFromPixels(前);

这是尝试用预定的颜色静态地为前景着色(我认为这是我想要做的,用透明的白色?!?):

ofPixelsRef fore = foreground.getPixelsRef();
ofColor c(0, 127);
for(int x = 0; x < foreground.getWidth(); x++) {
    for (int y = 0; y < foreground.getHeight(); y++) {
        fore.setColor(x, y, c);
    }
}

foreground.setFromPixels(fore);

两者都不是我想去的地方,但我认为它们正朝着正确的方向发展。 如果有人对何处继续有任何想法,我会全力以赴。

如果有一个干净的领导/示例,我会考虑转移到ofFbo类,甚至是GLSL。 随意发布香草C ++,我会看到我可以做些什么来将它移植到oF。

谢谢,

~Jesse

1 个答案:

答案 0 :(得分:0)

仅供参考,我在此页面找到了详细解决方案:http://forum.openframeworks.cc/index.php/topic,12899.0.html