Re: Precise bitmaps

*To*: mathgroup at smc.vnet.net*Subject*: [mg54840] Re: Precise bitmaps*From*: Stefano Taschini <taschini at gmail.com>*Date*: Fri, 4 Mar 2005 05:07:38 -0500 (EST)*References*: <cvrqg4$p55$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Jan, The quality of the raster engine in Mathematica is anyway rather poor, and I'd rather use an external tool. The whole procedure can be automatized. If you have ImageMagick and GhostScript installed on your Mac, you can use the following function Options[Rasterize] = {ImageSize -> 288}; Rasterize[g_, opts___?OptionQ] := With[{ f = OpenTemporary[], fullopts = Join[{opts}, Options@Rasterize]}, Close[f]; Export[First@f, g, "EPS"]; Run@StringForm["sh -l -c 'convert -resize `2` eps:`1` bmp:`1`'", First@f, Replace[Replace[ImageSize, fullopts], { n_Integer :> StringForm["`1`x`1`", n], {x_, y_} :> StringForm["``x``!", x, y]}]]; With[{bmp = Import[First@f, "BMP"]}, DeleteFile[First@f]; bmp]] For instance, you can rasterize the thorus of a previous reply, << Graphics`Shapes` g=Graphics3D[Torus[],Background->RGBColor[0,0,0]]; Show[Rasterize[g]] With the option ImageSize you can set max(width,height) Show[Rasterize[g, ImageSize -> 100]] You can also set exactly both width and height Show[Rasterize[g, ImageSize->{100,200}]] I tested the Rasterize function with Mathematica 5.1 on Mac Os X 10.3.8, but should work on any unix system, provided you have ImageMagick and GhostScript installed. Ciao, Stefano Jan G. Korvink wrote: > Dear All, > > I am battling to obtain a "precise" Raster[] of some Graphics[] objects. > There seems to be no straightforward way to do the conversion, so I tried: > > Export[ /tmp/myfile, Graphics[myGraphics], ImageSize -> {xmax,ymax} > myBitsPerUnit ] > g = Import[ /tmp/myfile ] > > from which I can unpack the Raster[]. Unfortunately the Raster[] > contains extra white space around the object, and no matter what I > select for "myfile" (I have tried all bitmap formats) I get a > consistently bad result. Furthermore, the Export/Import route is pretty > bad, since it is slow for large pictures. > > What works is to use Adobe Illustrator as the rendering engine. But this > is not nice! > > I do not want to implement a renderer, unless absolutely necessary, and > it seems silly since Mathematica has such an animal. > > Can anyone suggest an alternative route? > > Thanks in advance, Jan >