Borrar filtros
Borrar filtros

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

11 visualizaciones (últimos 30 días)
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

Respuestas (1)

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

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by