Clear Filters
Clear Filters

Hello Everyone, How can I check if someone uploads a video in MATLAB GUI using browse button instead of uploading an image?

2 views (last 30 days)
Hello Everyone, How can I check if someone uploads a video in MATLAB GUI using browse button instead of uploading an image? I am developing tool for image processing and I want to apply a check on the browse button so whenever the end user try to upload a video, it will show an error message.
  4 Comments
Rik
Rik on 19 Apr 2020
You can use fileparts to extract the extension and compare it to the list of extensions imread supports. I don't have a suggestion for how you could generate a list of video formats, but if you just want to throw an error when the user doesn't select an image, this strategy should work for you.

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 19 Apr 2020
Use try/catch on the imread. When the imread fails use try/catch on imfinfo; if it succeeds it was video (or possibly audio in container) and if it fails the file was not image or video.
  2 Comments
Walter Roberson
Walter Roberson on 19 Apr 2020
caution: Support for some formats is based on the contents of the file, not on the file extension. On some platforms if you rename an image file to the wrong extension then the code will detect the correct format instead of relying on the extension

Sign in to comment.


Mehmed Saad
Mehmed Saad on 19 Apr 2020
Edited: Mehmed Saad on 19 Apr 2020
Try this
[Filename,Pathname] =uigetfile(...
{'*.png','PNG (*.png)';
'*.tif;*.tiff','TIFF (*.tif,*.tiff)';
'*.gif','GIF (*.gif)';
'*.jpg;*.jpeg;*.jpe;*.jfif','JPEG (*.jpg,*.jpeg,*.jpe,*.jfif)';
'*.bmp','BMP (*.bmp)';},'File Selector')
He can only select these types of file and is not possible for him select any other file
Also you can go with this too
[Filename,Pathname] =uigetfile(...
{'*.png;*.jpg;*.jpeg;*.jpe;*.jfif;*.tif;*.tiff;*.gif;*.bmp',...
'Image File(*.png,*.jpg,*.jpeg,*.jpe,*.jfif,*.tif,*.tiff,*.gif,*.bmp)'},'File Selector');
  5 Comments

Sign in to comment.

Categories

Find more on Desktop in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!