1

我用 cinder/c++(我正在使用 Xcode)制作了一个程序,它允许您打开图像并将其显示在窗口中。我想知道如何使窗口的大小与打开的图片的大小相同?

这是我的代码:

#include "cinder/app/AppNative.h"
#include "cinder/gl/Texture.h"
#include "cinder/Text.h"
#include "cinder/ImageIo.h"

using namespace ci;
using namespace ci::app;
using namespace std;

class ConvexSpiralApp : public AppNative {
  public:
    void setup();
    void draw();

    gl::Texture myImage;
};

void ConvexSpiralApp::setup()
{
    try
    {
        ci::fs::path p = getOpenFilePath( "", ImageIo::getLoadExtensions());

        if( ! p.empty() )
        { // an empty string means the user canceled
            myImage = gl::Texture( loadImage( p ) );
        }
    }

    catch( ... )
    {
        console() << "Unable to load the image." << std::endl;
    }
}

void ConvexSpiralApp::draw()
{
    // clear out the window with black
    gl::clear( Color( 0, 0, 0 ) );

    gl::draw( myImage, getWindowBounds() );
}

CINDER_APP_NATIVE( ConvexSpiralApp, RendererGl )

大风

4

1 回答 1

0

我做的!

myImage = gl::Texture( processedImage );

setWindowSize(myImage.getWidth(), myImage.getWidth() );
于 2015-02-25T14:43:03.850 回答