Hello Everyone, How can I check if someone uploads a video in MATLAB GUI using browse button instead of uploading an image?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Rik
am 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.
Antworten (2)
Walter Roberson
am 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 Kommentare
Walter Roberson
am 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
Mehmed Saad
am 19 Apr. 2020
Bearbeitet: Mehmed Saad
am 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 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!