Hello Everyone, How can I check if someone uploads a video in MATLAB GUI using browse button instead of uploading an image?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2020-4-19
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.
回答(2 个)
Walter Roberson
2020-4-19
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 个评论
Walter Roberson
2020-4-19
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
2020-4-19
编辑:Mehmed Saad
2020-4-19
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!