Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exporting a bitmap in native resolution

93 views
Skip to first unread message

sibir

unread,
Feb 19, 2009, 3:35:03 AM2/19/09
to
HI all,
first I must mention that I am still on 5.2, but I suspect the problem
is universal. I have a ListDensityPlot which I want to export as a
bitmap (e.g., png) in native resolution, that is each data point
yielding one pixel.
I tried ImageSize and ImageResolution and googled around to no avail.
Anybody figured out how to do that?

Thanks, Martin

Jens-Peer Kuska

unread,
Feb 20, 2009, 5:47:52 AM2/20/09
to
Hi,

take the data from the DensityGraphics
and use

ImageMatrixQ[bm_?MatrixQ] := True
ImageMatrixQ[bm_?(MatrixQ[#, VectorQ] &)] := True
ImageMatrixQ[_] := False

MatrixToImage[data_?ImageMatrixQ] :=
Module[{dim, ny, nx, ch, mind, maxd, colorf},
dim = Dimensions[data];
{ny, nx} = Take[dim, 2];
If[3==Length[dim],
ch = Last[dim],
ch = 1
];
colorf = Switch[ch,
1, GrayLevel,
2, GrayLevel,
3, RGBColor,
4, RGBColor
];
{mind, maxd} = {Min[#], Max[#]} &[Flatten[data]];
If[Sqrt[#.#]&[{mind,maxd}-Round[{mind,maxd}]]<$MachineEpsilon,
{mind, maxd}=Round[{mind, maxd}]
];
If[Abs[maxd-mind]<$MachineEpsilon,
maxd=mind+1
];
Graphics[
Raster[
Developer`ToPackedArray[data], {{0, 0}, {nx, ny}}, {mind, maxd},
ColorFunction -> colorf
], AspectRatio -> Automatic,
PlotRange -> {{0, nx}, {0, ny}}, ImageSize -> {nx, ny}
]
]

the MatrixToImage[] function above.

Regards
Jens

0 new messages