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.
I have used precisely the same export/import trick as you in order to use the Mathematica rendering engine to generate bitmaps for use in image processing applications. My cure to the extra white space problem was to simply discard those pixels after Importing the bitmap, and to anticipate this loss of pixels by Exporting a slightly larger bitmap in the first place.
I have just tried to reproduce what I did using Mathematica 5.1 (for Windows) and find that the extra whitespace problem seems to have been cured in that version. However, here is (roughly) what I did to cure the problem in an earlier version of Mathematica:
Load a package for generating a pretty image.
<< "Graphics`Shapes`"
Generate an image (with a black background so you can see the extra white space when it is added), export, then import it. Notice that I export 1 pixel more in each dimension than I eventually need.
Now have a look at the contents of g2. The first part is the image data, so I have displayed only its dimensions. This shows which bits have to be changed if you crop the image. There may be an "official" way of doing this, but I haven't found it.
Make a copy of g2, and then hack it to crop the image. I am dropping the last pixel in each row, and also the last row of the image. I am doing this from memory, so if this prescription doesn't get rid of the white space then modify it appropriately.
> 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:
> 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.
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.
> 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:
> 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.