화면 캡처 예제









#include "ofApp.h"


ofImage tex;
ofTrueTypeFont f1;
bool _isRender = false;

//--------------------------------------------------------------
void ofApp::setup(){
    
    //캡처할 이미지 설정
    tex.allocate(320, 240, OF_IMAGE_COLOR);
    ofEnableAntiAliasing();
    
    //폰트 설정
    ofTrueTypeFont::setGlobalDpi(72);
    f1.loadFont("verdana.ttf", 13);
}

//--------------------------------------------------------------
void ofApp::update(){
    
    //키보드를 누르면 캡처
    if(_isRender == true)
    {
        tex.grabScreen(0, 0, 320, 240);
    }
}

//--------------------------------------------------------------
void ofApp::draw(){
    
    //테두리 그리기
    ofSetColor(0, 0, 0);
    ofNoFill();
    ofSetLineWidth(1);
    ofRect(1, 1, 320-1, 240-2);
    
    //캡처 된 이미지 드로우
    if(tex.isAllocated() ==true)
    {
        ofSetColor(255, 255, 255);
        tex.draw(320, 0);
    }
    
    
    //빨간 원
    ofSetColor(255, 0, 0);
    ofSetLineWidth(3);
    ofNoFill();
    ofCircle(mouseX, mouseY, 30);
    
    
    //정보 표시
    ofSetColor(255, 255, 255);
    f1.drawString("position x:" + ofToString(mouseX) + " , y:" + ofToString(mouseY), 10, 30);
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    _isRender = true;
}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){
    _isRender = false;
}


Yamecoder 야매코더_
C++(oF) 2015.02.02 23:16
Powerd by Tistory, designed by criuce
rss