0
リストから画像を使用してボタンを作成しようとしています。ボタンを中央に揃えたい私のコードは以下の通りです。私は、エラー "クラス" Fl_GIF_Image(const char *)ではない、 'イメージ'のメンバー 'W'の要求を取得し続けます。私は何をすべきかわからない。私はこれが画像の幅を与えると思った。何か案は?画像付きFLTKボタン
//
// 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()関数も使用していますか? –
私は画像のグループをフォルダに保存しておき、ランダムにボタン画像として使用する画像の1つを選択してください。 –
次にライブラリを見てください。 –