Azzera filtri
Azzera filtri

Creating an app using Matlabs App designer, need help displaying images in the app from and API.

11 visualizzazioni (ultimi 30 giorni)
I would like to display an image of the countries flag in the app associated to the name of the country selected in the drop down list. I can't seem to get it to work. This is my attempt so far, the image is in the API as a png file. The other fields populate, but the image will not.
data = webread('https://restcountries.com/v3.1/all');
val = app.Country_Select.Value;
switch val
case 'Jordan'
app.SpokenLanguageEditField.Value = data{1,1}.languages.ara;
app.PopulationSizeEditField.Value = data{1,1}.population;
app.AreaEditField.Value = data{1,1}.area;
app.RegionEditField.Value = data{1,1}.region;
app.Flagimage.ImageSource = (data{1,1}.flags.png);
end

Risposte (1)

Walter Roberson
Walter Roberson il 17 Lug 2023
[im, cmap] = imread(app.Flagimage.ImageSource);
if isempty(cmap)
if ndims(im) == 2
im = im(:,:,[1 1 1]); %gray to rgb
end
else
im = ind2rgb(im, cmap);
end
app.Flagimage.image = im;
  2 Commenti
Walter Roberson
Walter Roberson il 18 Lug 2023
It works when I test it.
data = webread('https://restcountries.com/v3.1/all');
val = 'Jordan';
switch val
case 'Jordan'
app.SpokenLanguageEditField.Value = data{1,1}.languages.ara;
app.PopulationSizeEditField.Value = data{1,1}.population;
app.AreaEditField.Value = data{1,1}.area;
app.RegionEditField.Value = data{1,1}.region;
app.Flagimage.ImageSource = (data{1,1}.flags.png);
end
[im, cmap] = imread(app.Flagimage.ImageSource);
if isempty(cmap)
if ndims(im) == 2
im = im(:,:,[1 1 1]); %gray to rgb
end
else
im = ind2rgb(im, cmap);
end
app.Flagimage.image = im;
imshow(app.Flagimage.image)

Accedi per commentare.

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by