open jpeg, png and bmp only

1 回表示 (過去 30 日間)
Andi Juwandi Karmita
Andi Juwandi Karmita 2017 年 1 月 9 日
hi .. i'm making a GUI image with JPEG compression. and I want to limit the system with input image is jpeg, png and bmp only. how should I do?

採用された回答

Walter Roberson
Walter Roberson 2017 年 1 月 9 日
Adapting Image Analyst's suggestion:
if ismember(ext, {'.png', '.bmp', '.jpg', '.jpeg'})
% It's an allowed extension
else
message = 'Only PNG, BMP, JPG, or JPEG format images are allowed.';
uiwait(warndlg(message));
end
And remember to add .jpg and .jpeg to the uigetfile call.
  1 件のコメント
Andi Juwandi Karmita
Andi Juwandi Karmita 2017 年 1 月 10 日
thanks, simple n work for me.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 1 月 9 日
編集済み: Image Analyst 2017 年 1 月 9 日
Try
if strcmpi(ext, '.png') || strcmpi(ext, '.bmp') || strcmpi(ext, '.jpg') || strcmpi(ext, '.jpeg')
% It's an allowed extension
else
message = 'Only PNG, BMP, JPG, or JPEG format images are allowed.';
uiwait(warndlg(message));
end
Better yet, just load a listbox full of the allowable images in the folder and let the user pick one. Also have a button to let them change folders. This is a nicer, kinder way to let users pick images, especially if their images are mostly all in one particular folder. See http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component
  1 件のコメント
Andi Juwandi Karmita
Andi Juwandi Karmita 2017 年 1 月 10 日
TERIMA KASIH = Thank You

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by