Filter löschen
Filter löschen

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

11 Ansichten (letzte 30 Tage)
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

Antworten (1)

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by