@sdaau wrote:
Please consider the compilable minimal (non)working example below - based on
examples/empty/emptyExample, standardMakefileandmain.cpp, and then:
ofApp.h#pragma once #include "ofMain.h" #define NUMLINES 100 class ofApp : public ofBaseApp{ public: ofTrueTypeFont myfont; int state = 0; int lx[NUMLINES], ly[NUMLINES], ll[NUMLINES], lw[NUMLINES], lr[NUMLINES], lg[NUMLINES], lb[NUMLINES]; unsigned int captFrame = 0; ofPoint captSize; ofImage imgCaptScreenshot; void setup(); void update(); void draw(); void mousePressed(int x, int y, int button); };
ofApp.cpp#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); myfont.load("arial.ttf", 32); // data for random lines: int w = ofGetWidth(), h = ofGetHeight(); for(int i=0; i<NUMLINES; i++) { lx[i] = (int) ofRandom(0, w); ly[i] = (int) ofRandom(0, h); ll[i] = (int) ofRandom(0, ((w>h) ? h/4 : w/4) ); lw[i] = (int) ofRandom(1, 11); lr[i] = (int) ofRandom(0, 255); lg[i] = (int) ofRandom(0, 255); lb[i] = (int) ofRandom(0, 255); } } //-------------------------------------------------------------- void ofApp::update(){ if (state == 1) { //draw nothing, just switch after a sec if (ofGetFrameNum() > captFrame + 60) { state = 2; } } } //-------------------------------------------------------------- void ofApp::draw(){ if (state == 0) { ofBackgroundGradient(ofColor::blue, ofColor::violet); for(int i=0; i<NUMLINES; i++) { ofSetColor(lr[i], lg[i], lb[i]); ofSetLineWidth(lw[i]); ofDrawLine(lx[i], ly[i], lx[i]+ll[i], ly[i]+ll[i]); } ofSetColor(ofColor::yellow); myfont.drawString(" TESTING ", 100,100); } if (state == 1) { //draw nothing, just switches after a sec } if (state == 2) { // reproduce screenshot ofSetColor(ofColor::white); // set color to white imgCaptScreenshot.draw(0,0, captSize.x, captSize.y); //draw image (tinted white, i.e. untinted); //~ imgCaptScreenshot.draw(0,0, imgCaptScreenshot.getWidth(), imgCaptScreenshot.getHeight()); //same effect as previous command } } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ captFrame = ofGetFrameNum(); captSize = ofPoint(ofGetWidth(), ofGetHeight()); imgCaptScreenshot.grabScreen(0,0, captSize.x, captSize.y); ofLogNotice() << "::mousePressed " << captFrame << " " << captSize.x << " " << captSize.y ; state = 1; }In this application, first semi-random content is generated; upon mouse click, this content is captured into
ofImageviagrabScreen(), while an empty (gray) background is shown for about a second; after the one second is expired, then the captured screenshot is drawn back. The problem I have, is that the original content is rendered like this:... however, the reproduced screenshot is rendered like this:
... which is clearly of the wrong size (or scale).
What am I doing wrong, and how can I reproduce a screenshot at exactly the same size and scale as the screen?
Posts: 2
Participants: 1

