From hb at stat.berkeley.edu  Fri Jan 26 02:35:15 2007
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Thu, 25 Jan 2007 17:35:15 -0800
Subject: [Rd] Inferring dimensions on bitmap device from par()
Message-ID: <59d7961d0701251735i5f71f989g8c16704e7605d799@mail.gmail.com>

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



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