【发布时间】:2011-06-13 03:01:05
【问题描述】:
这很可能是 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 fig 为具有高分辨率透明背景的 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 版本。
【问题讨论】:
-
只是一个简短的评论。我只使用了几次透明 bkg,但总是在 RGBA 通道表示中这样做。
-
在版本 7 上,
x^2 + y^2图形正确渲染,第一组球体以透明度导出。因此,我添加了mathematica-8 标签。 -
@Mr.Wizard,您的意思是 7.0.0 版吗?我在 7.0.1 版本中尝试了
x^2 + y^2,Res_400.png 与 Res_500.png 和 Res_600.png 显示相同。感谢您添加标签。 -
@belisarius,RGBA 通道表示是什么意思?我检查了
ColorSpace,允许的值为“灰度”、“RGB”、“CMYK”和“HSB”。 -
我得到的输出见下面我的答案。
标签: image wolfram-mathematica plot mathematica-8