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

Scaling manually works, but not using ofScale

$
0
0

@br0mid wrote:

Hi, I’m scaling an image by dragging the corners and the result is a bit strange. As I scale, I keep track of my new width and height. When I draw using ofScale and the scale ratio, I notice an offset between my image and the border. When I don’t use ofScale and just draw the image using the scaled width and height everything works.

Not using ofScale:


ofPushMatrix();
ofSetColor(255,255,255);
ofTranslate(pic->imageCenter.x, pic->imageCenter.y);
ofRotateZRad(pic->angle);
pic->image.draw(-1*pic->width/2, -1*pic->height/2, pic->width, pic->height); //Using scaled width and height![24%20PM|660x500](upload://npSyPZMqEEEbl1XcvuFaq2yLbMu.jpeg) ![26%20PM|647x500](upload://2Ec3s32cdc37EYDFMKA9kNsHYyG.jpeg) 
ofPopMatrix();

ofPushMatrix();
ofTranslate(pic->imageCenter.x, pic->imageCenter.y);
ofRotateZRad(pic->angle);
ofSetColor(255,0,0);
ofNoFill();
ofSetLineWidth(3);
ofDrawRectangle(-1*pic->width/2, -1*pic->height/2, pic->width, pic->height);

Using ofScale:


ofPushMatrix();
ofSetColor(255,255,255);
ofTranslate(pic->imageCenter.x, pic->imageCenter.y);
ofScale((pic->width/pic->image.getWidth()), (pic->height/pic->image.getHeight()), 0); //Scale using ratio
ofRotateZRad(pic->angle);
pic->image.draw(-1*pic->width/2, -1*pic->height/2); //Using original image dimensions
ofPopMatrix();

ofPushMatrix();
ofTranslate(pic->imageCenter.x, pic->imageCenter.y);
ofRotateZRad(pic->angle);
ofSetColor(255,0,0);
ofNoFill();
ofSetLineWidth(3);
ofDrawRectangle(-1*pic->width/2, -1*pic->height/2, pic->width, pic->height);

pic is just an object that contains the original image, scaled width, scaled height, and angle.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles