Matlab:用透明背景保存图形 [英] Matlab: Save figure with transparent background

查看:1985
本文介绍了Matlab:用透明背景保存图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个情节,我将背景设置为透明:

I have a plot and am setting the background to transparent by:

set(gcf, 'Color', 'None');
set(gca, 'Color', 'None');

当我尝试保存图像(来自观看者)时,我保存为.png,但是它以白色背景保存。如何用透明背景保存?

When I try to save the image (from the viewer), I save as a .png, but it saves with a white background. How can I save it with the transparent background?

谢谢

推荐答案

令人失望但是,MATLAB的默认 saveas print 命令无法很好地处理透明事物。你必须用一些背景保存它,然后通过 imread / imwrite 或其他一些工具转换它。

It is disappointing but, MATLAB's default saveas and print commands cannot deal with transparent things very well. You'll have to save it with some background and then convert it either through imread/imwrite or some other tool.

有些工具可能会有所帮助:

There are some tools that might be helpful:

  • Export fig http://www.mathworks.com/matlabcentral/fileexchange/23629
  • svg export http://www.mathworks.com/matlabcentral/fileexchange/7401-scalable-vector-graphics-svg-export-of-figures

我更喜欢矢量图形,所以在需要透明度时使用svg exports。如果你确实有位图,请使用 imwrite(bitmapData,'a.png','png','transparency',backgroundColor)

I prefer vector graphics, so use svg exports when transparency is needed. If indeed you have a bitmap, use imwrite(bitmapData, 'a.png', 'png', 'transparency', backgroundColor).

这篇关于Matlab:用透明背景保存图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆