这很可能是 Mathematica 8.0.1 和其他版本中的错误。让我们尝试以下方法:
Table[
Export[
"Res_" <> ToString[r] <> ".png", Rasterize[
Style[x^2 + y^2, 40],
Background -> None,
ImageResolution -> r
],
Background -> None],
{r, {20, 40, 100, 300, 400, 500, 600}}
]
这是我获得的屏幕截图:
首先要注意的是最后两张图片的尺寸错误。这在某种程度上很好,因为我对 300 或更高的分辨率感到满意。现在看看这个:
in = 72;
G3D = Graphics3D[AspectRatio -> 0.925, Axes -> {True, True, True},
AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, AxesStyle -> Directive[10, Black],
BaseStyle -> {FontFamily -> "Arial", FontSize -> 12}, Boxed -> False,
BoxRatios -> {1, 1, 1}, LabelStyle -> Directive[Black],
ImagePadding -> All, ImageSize -> 5 in, PlotRange -> All,
PlotRangePadding -> None, TicksStyle -> Directive[10],
ViewPoint -> {2, -2, 2}, ViewVertical -> {0, 0, 1}, Background -> None
];
surf = Show[
Graphics3D[Sphere[{0, 0, 0}, 1], Background -> None,
AxesLabel -> {"x", "y", "z"}], Options[G3D]
];
fig = Show[surf, AxesStyle -> Directive[Opacity[0]],
Background -> None
];
我希望将Export
其设置为具有高分辨率透明背景的 png 文件。这是我对总是有问题的 Mathematica 的蹩脚尝试。
Table[
Export[
"Res_" <> ToString[r] <> ".png",
Rasterize[fig, ImageResolution -> r, Background -> None],
Background -> None
], {r, {20, 40, 100, 300, 400, 500}}
]
这是几个 png 文件的屏幕显示。
他们都提出了预期的解决方案:)。但是我的透明背景怎么了?我已经通过我的代码指定了很多次Background -> None
,但这并不想工作。我浏览了网络,发现了这个:
http://forums.wolfram.com/mathgroup/archive/2009/Feb/msg00943.html
让我们使用这个想法。
bgImage = Image[ConstantArray[{0, 0, 0, 0}, Reverse[ImageDimensions[fig]]],
ColorSpace -> "RGB"];
compImage = ImageCompose[bgImage, fig];
Table[Export["Res_" <> ToString[r] <> ".png",
Rasterize[compImage, ImageResolution -> r, Background -> None],
Background -> None], {r, {20, 40, 100, 300, 400, 500}}]
没有背景!!!:) 伟大的。但是我的图像大小发生了什么变化?分辨率在增加,但图像尺寸开始减小。我真的一直在纠结这个问题太久了。我希望你们中的某个人能对这个 Mathematica 错误有所了解,并能找到一个 hack 以实现高分辨率的透明背景 PNG。如果您找到答案,请提及你们正在使用的 Mathematica 版本。