PDA

View Full Version : Save Plots and TV displays as JPEGS



green12
05-18-2009, 09:25 AM
Any idea how to take my plots and save them as jpegs and/or take my TV displays and save them as jpegs? Thanks.


(I have been trying to use image_create and image_write but I am confused how to use the colormap correctly to preserve the color in my image and not default to grayscale)

rwagner
05-18-2009, 11:49 AM
Hi green12, Please take a look at the following sample code.
-Ryan



PV-WAVE v9.01 UNIX/WINDOWS

% Windows NT version 5.1 build 2600
9.01> plot, indgen(10)
9.01> r = TVRD(True=3)
9.01> a = IMAGE_CREATE(r)
9.01> s = image_write('C:\output.jpg', a)

hcrisp
05-18-2009, 11:52 AM
Something like this?



file = 'img.jpg'
file_type = 'JPEG'
frame = TVRD(0, 0, !D.x_size, !D.y_size)
ct = !D.table_size-1
pal = BYTARR(3, 256)
TVLCT, r, g, b, /GET
pal(0, 0:ct) = r
pal(1, 0:ct) = g
pal(2, 0:ct) = b
image = IMAGE_CREATE(frame, COLORMAP=pal, COLORMODEL=1, $
FILE_NAME=file, FILE_TYPE=file_type)
st = IMAGE_WRITE(file, image, COMPRESS=compress, $
FILE_TYPE=file_type)

hcrisp
06-26-2009, 01:21 PM
Just as a follow up -- I was looking for a way to create the output image file solely in memory so I can embed it in another file. This does not appear possible without a write to an intermediate image file.

This is because for popular formats like BMP, GIF, JPEG, and PNG, a call to IMAGE_WRITE eventually calls 'fileio_write_image', which is closed source. I cannot stop and grab the binary data before it gets written to disk.

Is writing the temporary file the only way to get what I am after? It seems an unnecessary step.



plot, RANDOMU(s, 2000)
file = 'img.jpg'
frame = TVRD(0, 0, !D.x_size, !D.y_size)
image = IMAGE_CREATE(frame, FILE_NAME=file, FILE_TYPE='JPEG')
st = IMAGE_WRITE(file, image, FILE_TYPE='JPEG')
OPENR, unit, file, /GET_LUN
fs = LFSTAT(unit)
bytes = BYTARR(LONG(fs.size))
READU, unit, bytes
FREE_LUN, unit
SPAWN, 'del ' + file
; The binary values in are now in memory
; I can modify them and write them out again using WRITEU ...