Open a file in a program or application and save in another format

2 次查看(过去 30 天)
How can a file (i.e. a .jpg image) be opened in a program (i.e. MS. Paint) and saved in a different format (i.e., TIF)?
I'd also appreciate hints to perform more tasks such as resizing the image or using other functions of the program in which the file is opened.
  2 个评论
Geoff Hayes
Geoff Hayes 2022-12-23
@Vahid Atashbari - please clarify how your question relates to MATLAB. Why do you want the file to be opened in MS Paint? Are you also asking how to resize (or do whatever) the image using MS Paint too?
Vahid Atashbari
Vahid Atashbari 2023-1-8
Geoff,
The question is broadly asking about loading other programs/applications in Matlab script and performing tasks on such applications as part of the code. The MS Paint was an example; you can make any other case/example.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2023-1-8
Windows, MacOS and Linux versions of MATLAB can all use system() to invoke command lines. However system() does not permit any interactive control.
All three versions can use the Java interface to call the Java Robot class. That allows simulating key presses and button pushes and moving the cursor, and so allows control of programs which have a window open and visible. However the Robot is poor at figuring out what is currently showing, so it is poor at reading what is currently displayed and reacting to it.
Windows MATLAB offers calls to activeX controls, which uses a formal data communication interface. Programs such as Excel offer a fair bit of control through the interface. But the program has to have been specifically written to support the interface.
Windows MATLAB offers an interface to .NET interfaces. These are in some ways similar to activeX but the range of interfaces offered is improved.
In particular there is an available .net interface System.Diagnostics.Process which offers some flexibility in creating processes and communicating with them. But Windows only.
Some software packages offer DLL that give interfaces to control the program from C or C++. All versions of MATLAB offer the ability to call into precompiled C or C++ DLL provided the interface is defined properly.

更多回答(1 个)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022-12-23
You can try with the following functions to save image data - saveas() in an image file and open in MS applications using winopen():
(1) To save your image data displayed in a Figure window using: saveas(gcf, 'IMAGE', 'jpg')
(2) To open the file from MATLAB: winopen('IMAGE.jpg')
  3 个评论
DGM
DGM 2023-1-8
Save images using imwrite() instead of figure capture.
imwrite(myimagevariable,'outputfile.png')
Using figure capture will usually result in the image being crudely resized with nearest-neighbor interpolation, some amount of excess white padding added, and the image potentially changing type (e.g. a binarized, indexed, or grayscale image being converted to RGB). It's destructive, poorly-controlled, and typically unnecessary.
JPG is also destructive and often unnecessary. Using JPG as an intermediate step between the workspace and a (typically) lossless format like TIFF largely defeats the purpose of using a lossless format.
For the specific case of MSPaint, I imagine most of the work that can hypothetically be done programmatically in Paint can also just be done in MATLAB.
For the general case of controlling other applications, I don't know if an arbitrary application supports desired operations through a command line interface or if there is some API to do it. That would require specifics. If you can write an external script to do it, then there you can always run that script via MATLAB.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by