Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Proportionally scale and mask an image

$
0
0

@sjespers wrote:

Hi there,

I'd like to proportionally scale and mask an image. When I try to scale an image with a mask the mask is never correct.

void myApp::loadImage(){
    if (image.load("https://mir-s3-cdn-cf.behance.net/projects/404/4a231a51108355.Y3JvcCwyMjc2LDE3ODEsMTUxLDk1NQ.jpg")) {

        ofLogNotice("myApp::ImageLoaded") << image.getWidth() << "x" << image.getHeight();

        w = image.getWidth();
        h = image.getHeight();

        scaleRatio = w/itemWidth;
        itemHeight = h/scaleRatio;

        ofRectangle myRectMask;
        myRectMask.x = 0;
        myRectMask.y = 0;
        myRectMask.width = itemWidth-20;
        myRectMask.height = itemHeight-20;

        fbo.allocate(itemWidth,itemHeight,GL_RGBA);

        fbo.begin();
        {
            ofClear(0,0,0,0);
        }
        fbo.end();

        fbo.begin();
        {
            ofClear(0,0,0,0);
            ofSetColor(255);
            ofDrawRectRounded(myRectMask, 10, 10, 10, 10);
        }
        fbo.end();

        image.getTexture().setAlphaMask(fbo.getTexture());

    } else {
        //image failed to load
    };
}

And then I draw the image with
image.draw(10, 10, itemWidth, itemHeight);

What am I missing or doing wrong?

Thanks!
Serge

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles