convertScreenUnits {imageUtilities}R Documentation

Attempt to convert between npc, inches, and pixels on the screen.

Description

Attempt to convert between npc, inches, and pixels on the screen.

Usage

  convertScreenUnits(value, from, to,
    type = c("width", "height"))

Arguments

value

value to convert

from

unit to convert from. See Details.

to

unit to convert to. See Details.

type

either 'width' or 'height'. Only of use for 'npc' conversions – whether you want to return a fraction of the height or of the width.

Details

The available units are:

inches

Inches

npc

Normalised Parent Coordinates: the entire monitor has dimensions (1,1).

pixels

pixels

** The conversions are rough only and not exact! Also, 'npc' conversions may screw up with dual monitor! **

The conversion between pixels and inches uses imageUtilities.option('ppi') (pixels per inch), which is default 96.

The conversion between pixels or inches and screen size uses the function getScreenResolution, which doesn't always work. If the code is unable to return the screen resolution, a default value of imageUtilities.option('default.screen.resolution') is used (currently 1280 x 1024).

Value

the converted unit

See Also

imageUtilities.option

Other units: getPPI, getScreenResolution, unitType

Examples

# convert 7 screen inches to screen pixels (approx).
convertScreenUnits(7,from='inches',to='pixels')
# find out what half the screen width is in inches
convertScreenUnits(.5,from='npc',to='inches',type='width')
# find out what fraction of the screen height 2 inches is.
convertScreenUnits(2,from='inches',to='npc',type='height')

[Package imageUtilities version 1.0.3 Index]