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

From: Henrik Bengtsson <hb_at_stat.berkeley.edu>
Date: Fri 26 Jan 2007 - 01:35:15 GMT


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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Jan 26 12:46:27 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 26 Jan 2007 - 07:31:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.