【问题标题】:FLTK button with an image带有图像的 FLTK 按钮
【发布时间】:2017-09-21 11:07:44
【问题描述】:

我正在尝试使用列表中的图像创建一个按钮。我希望按钮居中。我的代码如下。我不断收到错误“请求‘image’中的成员‘W’,它是非类类型‘Fl_GIF_Image(const char*)”。我不确定我应该怎么做。我认为这会给出图像的宽度。有什么想法吗?

//
//  source.cpp
//  labapril20
//
//  Created by Kate Godfrey on 4/20/17.
//  Copyright (c) 2017 Kate Godfrey. All rights reserved.
//

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_GIF_Image.H>
#include <iostream>
#include <time.h>
#include <vector>
#include <cstdio>

using namespace std;

int main(int argc, char **argv) {
    srand(time(NULL)); // set random seed based on current time
    vector<string> filenames {"cloudy.gif","fog.gif","lightning.gif","partsunny.gif","rain.gif","sunny.gif"};

    string filename = filenames.at(rand() % filenames.size()); // get randome filename
    cout << "Image File: " << filename << endl; // for debugging

    // Start add code for image on button
    Fl_GIF_Image image(const char* filename);

    Fl_Window *window = new Fl_Window(image.W(), image.H());

    Fl_Button *button = new Fl_Button(0, 0, image.W(), image.H(), filename);
    //button->image();

    //cout << image.w() << "X" << image.h() << endl; // for debugging

    // End code for image on button
    window->end();
    window->show(argc, argv);
    return Fl::run(); 



}

【问题讨论】:

  • 我对 FLTK 一无所知,但为什么要使用原始拥有指针呢?为什么还要使用过时的 rand() 函数?
  • 我将一组图像保存在一个文件夹中,我希望它随机选择其中一个图像用作按钮图像
  • 然后看看 库。
  • 问题不在于随机文件的选择。将图像分配给按钮
  • 宽高小写w,小写h

标签: c++ image button gif fltk


【解决方案1】:

要找一个也上Dr.Moore的课的人不容易哈哈 试试这个

Fl_Window* w = new Fl_Window(340, 180);
Fl_GIF_Image* gif = new Fl_GIF_Image("fog.gif");
Fl_Button* Btn01 = new Fl_Button(20,40,gif->w(),gif->h());
Btn01->image(gif);

希望它有效!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-20
    • 2016-09-01
    • 2011-02-11
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    相关资源
    最近更新 更多