Effacer les filtres
Effacer les filtres

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

11 vues (au cours des 30 derniers jours)
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

Réponses (1)

Walter Roberson
Walter Roberson le 17 Juil 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 commentaires
Aaron
Aaron le 18 Juil 2023
I'm recieving an erroe using this code "Error using imread. File does not exist.
Walter Roberson
Walter Roberson le 18 Juil 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)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by