How to save image , in the image type it is being fetched.
1 view (last 30 days)
Show older comments
In my work, I have provided a GUI interface to select a image to be watermarked and after watermarking process i have to save the image,
Now the issue is if I save it using imwrite then the image type will be fixed like either .BMP or .JPG
how to provide, the choice that user can select image format and image is saved in that same type.
I am not getting, how the code will be done
Plz help!!!
0 Comments
Answers (1)
Image Analyst
on 3 May 2013
Use menu(), then depending on which button was selected, use sprintf() to write the proper extension into the filename. Let me know if you can't figure it out and I can give a demo.
2 Comments
Image Analyst
on 3 May 2013
Edited: Image Analyst
on 3 May 2013
If you're having trouble, here is the code:
folder = 'C:/Users/ankita/Documents';
baseFileName = 'myOutputImage';
button = menu('Use which format for the image file?', 'PNG', 'BMP', 'TIF', 'JPG');
if button == 1
extension = 'PNG';
elseif button == 2
extension = 'BMP';
elseif button == 3
extension = 'TIF';
else
extension = 'JPG';
end
% Append extension to the base file name.
baseFileName = sprintf('%s.%s', baseFileName, extension)
% Prepend the folder to get the full file name.
fullFileName = fullfile(folder, baseFileName)
imwrite(imageArray, fullFileName);
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!