Skip to content

readPNG gives warnings and doesn't execute sample code from help files

7 messages · Joris Meys, Simon Urbanek, Ben Bolker

#
Dear all,

I noticed in the latest R version (R.2.12.1) that the readPNG gives
following warning when running the example code in the help file (or
when using any other png for that matter) :

50: In rasterImage(img, 1.2, 1.27, 1.8, 1.73) :
  Per-pixel alpha not supported on this device

No picture is shown, and code I used to be able to run, doesn't run any more.
R version 2.12.1 (2010-12-16)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United
States.1252

attached base packages:
[1] grDevices datasets  splines   graphics  stats     tcltk     utils
   methods   base

other attached packages:
[1] png_0.1-2       svSocket_0.9-51 TinnR_1.0.3     R2HTML_2.2
Hmisc_3.8-3     survival_2.36-2

loaded via a namespace (and not attached):
[1] cluster_1.13.2  grid_2.12.1     lattice_0.19-13 svMisc_0.9-61
tools_2.12.1
#
Joris,
On Feb 14, 2011, at 10:05 AM, Joris Meys wrote:

            
You may want to use a device that supports alpha. The R logo in the example uses alpha so are probably the images you are using. If you don't want to (or can't) use a device that supports alpha, you'll have to flatten the alpha, - i.e. plot just img[,,1:3]
However, most images don't have color where alpha is zero, so you'll have to replace it with the background color, e.g.:
r = as.raster(img[,,1:3])
r[img[,,4] == 0] = "white"

Cheers,
Simon
#
I believed the standard plotting device on R in 2.12.1 would support
per-pixel alpha. It does support alpha, as

 plot(1:2,type="l")
 polygon(c(1,1,2,2),c(1,2,2,1),col=rgb(60,100,60,60,maxColorValue=255))

plots correctly. Which device should I use then?

Cheers
Joris

On Mon, Feb 14, 2011 at 5:30 PM, Simon Urbanek
<Simon.Urbanek at r-project.org> wrote:

  
    
#
Joris Meys <jorismeys <at> gmail.com> writes:
See 

http://developer.r-project.org/Raster/raster-RFC.html

(near the bottom of the page, where it explains that the
Windows device supports alpha but not per-pixel alpha ...)

 cheers
    Ben Bolker
#
Thx again for your answer. I've tried X11() - which is supposed to
support alpha per pixel as well, but on Windows that's still no avail.
So basically, on Windows I can forget about alpha?

Cheers
Jors
On Tue, Feb 15, 2011 at 2:20 PM, Ben Bolker <bbolker at gmail.com> wrote:

  
    
#
Sorry, correction. X11() is not supposed to do that. So on Windows,
per-pixel alpha is no option apparently. Any chance this will be
implemented in the future?

Cheers
Joris

PS : also thx to Simon for his helpful answer earlier.
On Tue, Feb 15, 2011 at 2:40 PM, Joris Meys <jorismeys at gmail.com> wrote:

  
    
#
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 02/15/2011 08:44 AM, Joris Meys wrote:
Hmmm.

  I think your best bet would be
http://cran.r-project.org/web/packages/Cairo/index.html ... ?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1ai+oACgkQc5UpGjwzenPNWQCgiMQwXc9t/8DnziWOZJbk1Aqw
X+IAnA9G+VwcknZPisZ5pqVICxEQ+L++
=iPcR
-----END PGP SIGNATURE-----