필터 지우기
필터 지우기

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

조회 수: 11 (최근 30일)
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

답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by