如何使用Alpha通道将图打印/保存为png文件?
我正在使用Octave 4.2.2,Ubuntu 18.04 64bit和graphics_toolkit fltk
t = [0:0.01:2*pi]; x = sin (t);
plot (t, x);
set(gcf, 'Position', [10, 10, 500, 500]);
print(gcf,'-dpngalpha', 'myplot.png');
我收到一个错误错误:打印:未知设备pngalpha错误:在第265行第5列从print_parse_opts调用在第316行第8列打印
请注意:Octave版本是5.2,此问题在下面解决。
(更新:也可以在这里看到Sancho的一个不错的答案:在从Octave导出的绘图中具有透明背景)
通常,仍不完全支持在八度中添加透明度。我的建议是照常生成图像,并使用外部工具添加透明度(system
如果您希望将其作为脚本的一部分,则可以在八度范围内通过函数调用透明度)。
imagemagick套件可以通过convert命令执行您想要的操作,例如
convert myplot.png -fuzz 50% -transparent white myplot_transparent.png
(从这里拍摄)
如果您想产生许多“层”,其中一些层具有透明性,然后将它们覆盖(大概是您首先想要的透明性),则还可以通过以下方式通过imagemagick进行操作:
convert bottomlayer.png toplayer.png -compose over -composite out.png
因此,一个完整的八度示例可能看起来像这样:
t = [0:0.01:2*pi];
% Create bottom layer (no transparency needed)
plot (t, sin(t), 'r', 'linewidth', 3);
set(gcf, 'Position', [10, 10, 500, 500]);
axis([-1, 7, -1, 1]);
set(gca, 'Position', [0.1, 0.1, 0.8, 0.8]);
saveas(gcf, 'bottom.png');
% Create top layer, and make transparent (via imagemagick)
plot (t, cos(t), 'g', 'linewidth', 3);
set(gcf, 'Position', [10, 10, 500, 500]);
axis([-1, 7, -1, 1]);
axis off;
set(gca, 'Position', [0.1, 0.1, 0.8, 0.8]);
saveas(gcf, 'top.png');
system('convert top.png -fuzz 10% -transparent white top.png');
% Combine layers
system('convert bottom.png top.png -compose over -composite result.png');
%Visualise result in octave
imshow result.png
结果图像:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句