[Rd] Inferring dimensions on bitmap device from par()

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jan 26 07:40:09 CET 2007


You asked

> (or ultimately the dimension of the generated plot in pixels) without
> know which of png(), jpeg() or bitmap() was used?

That is determined by arguments 'width' and 'height' in the call to the 
device, and for the first two it is in pixels and for the third it is in 
inches.  Internally these are just numbers, and in particular the R 
graphics system does not know the resolution to be used in pixelization. 
Since some graphics parameters assume 'inches' and some 'pixels', 
assumptions have to be made.  png() assumes 96dpi and postscript() assumes 
72dpi.

You had the information you asked for, so why not just use it?
R is not claiming to be your keeper.

On Thu, 25 Jan 2007, Henrik Bengtsson wrote:

> Hi,
>
> I am trying to infer the dimension of an opened bitmap (png, jpeg,
> bitmap device...) from par() parmeters.  From the help on par(), I
> found that:
>
>> dim <- c(400, 200)
>> png("foo.png", width=dim[1], height=dim[2])
>> dim2 <- par("din") * par("cra") / par("cin")
>> dev.off()
>> dim2
> [1] 399.9999 199.9999
>
> I've tried the above on Rv2.4.1 on WinXP and Linux with png() and
> jpeg() and the precision is good enough.  However, when I turn to the
> bitmap() device, I found the following:
>
>> s <- 3;  # Multiple of 72pt (default value of argument 'res' of bitmap())
>> res <- s*72;
>> bitmap("foo.png", width=dim[1]/res, height=dim[2]/res, res=res)
>> dim2 <- par("din") * par("cra") / par("cin")
>> dev.off()
>> dim/dim2
> [1] 3 3
>
> That is, dim/dim2 is not one, but equal to the multiple 's'.   I
> understand that this is because bitmap() is not a device per se and
> utilized postscript() plus a call to ghostscript.  But still, does
> anyone know if it is possible to infer the correct resolution
>
> res2 <- s * par("cra") / par("cin")
>
> (or ultimately the dimension of the generated plot in pixels) without
> know which of png(), jpeg() or bitmap() was used?  I know of
> par("ps"), but its "unit" is device specific.
>
> Thanks
>
> Henrik
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list