The READ_PNG routine reads the image contents of a Portable Network Graphics (PNG) file and returns the image in an IDL variable. If the image contains a palette (see QUERY_PNG), it can be returned as well in three IDL variables. READ_PNG supports 1, 2, 3 and 4 channel images with channel depths of 8 or 16 bits.
| Note |
| Note |
| Note |
Result = READ_PNG ( Filename [, R, G, B] [,/ORDER] [, /VERBOSE] [, /TRANSPARENT] )
or
READ_PNG, Filename, Image [, R, G, B] [,/ORDER] [, /VERBOSE] [, /TRANSPARENT]
| Note |
For 8-bit images, Result will be a two- or three-dimensional array of type byte. For 16-bit images, Result will be of type unsigned integer (UINT).
A scalar string containing the full pathname of the PNG file to read.
Named variables that will contain the Red, Green, and Blue color vectors if a color table exists.
Set this keyword to indicate that the rows of the image should be read from bottom to top. The rows are read from top to bottom by default. ORDER provides compatibility with PNG files written using versions of IDL prior to IDL 5.4, which wrote PNG files from bottom to top.
Produces additional diagnostic output during the read.
Returns an array of pixel index values that are to be treated as "transparent" for the purposes of image display. If there are no transparent values then TRANSPARENT will be set to a long-integer scalar with the value 0.
Create an RGBA (16-bits/channel) and a Color Indexed (8-bit/channel) image with a palette:
rgbdata = UINDGEN(4,320,240) cidata = BYTSCL(DIST(256)) red = indgen(256) green = indgen(256) blue = indgen(256) WRITE_PNG,'rgb_image.png',rgbdata WRITE_PNG,'ci_image.png',cidata,red,green,blue ;Query and read the data names = ['rgb_image.png','ci_image.png','unknown.png'] FOR i=0,N_ELEMENTS(names)-1 DO BEGIN ok = QUERY_PNG(names[i],s) IF (ok) THEN BEGIN HELP,s,/STRUCTURE IF (s.HAS_PALETTE) THEN BEGIN img = READ_PNG(names[i],rpal,gpal,bpal) HELP,img,rpal,gpal,bpal ENDIF ELSE BEGIN img = READ_PNG(names[i]) HELP,img ENDELSE ENDIF ELSE BEGIN PRINT,names[i],' is not a PNG file' ENDELSE ENDFOR END
Introduced: 5.2