I want to save this image with a gray background, but when I open the .jpg file, it appears with a white background.
h = gcf;
ax = gca;
ax.Color = [0.5 0.5 0.5];
saveas(h, 'image.jpg');
What is the solution to save the background color to the image file as well?

 Akzeptierte Antwort

Image Analyst
Image Analyst am 14 Aug. 2017
Bearbeitet: Image Analyst am 31 Mär. 2022

2 Stimmen

Try getframe().
Starting with r2020b you can use exportgraphics():
exportgraphics(gca, fileName);
It should look just like it looks on screen.

Weitere Antworten (1)

Navid Ghajarnia
Navid Ghajarnia am 31 Mär. 2022

1 Stimme

The answer to this questionis given here:
Please execute the following command before you save the figure in the PNG format.
set(gcf, 'InvertHardcopy', 'off');
Then, you can save the plot as it is displayed.

Kategorien

Mehr zu Printing and Saving finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by