【IDL】如何保存IDL绘制的图像或图形
作者:互联网
IDL进行可视化时绘制方式有直接图形法、对象图形法;显示有灰度显示、伪彩色显示、真彩色显示;文件保存又分为jpg、bmp、tif等各个格式,组合起来应用还真让人有点儿头疼。
下面对常用绘图及保存方式进行了总结,依次在显示了直接图形法下绘制灰度、伪彩色图像;对象图形法下绘制灰度、彩色图像;同时将其保存为jpg、bmp和tiff文件。
;保存为图像文件
;windowID-图像显示窗体ID
;windowDims-图像显示窗体大小
;imageFile-保存结果文件名
;type - 保存文件类型,默认为jpg
; 1:JPG; 2:bmp; 3:tiff
PRO SAVEDIFFERENTIMAGE, windowID,windowDims, imageFile,type=type
;置顶为当前显示
WSET,windowID
;拷屏操作
data = TVRD(0,0,windowDims[0],windowDims[1],/true)
CASE type OF
1: WRITE_JPEG, imageFile, data,/true, quality=100
2: WRITE_BMP,imageFIle,data,/RGB
3: WRITE_TIFF,imageFile, data,ORIENTATION =4
ELSE:
ENDCASE
END
;保存显示的图形
PRO TESTSAVEIMAGE
winSize = [420,420]
;直接图形法
data = DIST(400)
;灰度绘制显示
DEVICE,decomposed =1
WINDOW,1,xsize = winSize[0],ysize = winSize[1]
TV,data
;直接保存为jpeg
SAVEDIFFERENTIMAGE,1,winSize, 'c:\temp\1.jpg',/type
;直接保存为tiff
SAVEDIFFERENTIMAGE,1,winSize, 'c:\temp\1.bmp',type =2
;直接保存为bmp
SAVEDIFFERENTIMAGE,1,winSize, 'c:\temp\1.tif',type =3
;伪彩色显示
DEVICE,decomposed =0
LOADCT,5
WINDOW,2,xsize = winSize[0],ysize = winSize[1]
TV,data
;直接保存为jpeg
SAVEDIFFERENTIMAGE,2,winSize, 'c:\temp\2.jpg',/type
;直接保存为tiff
SAVEDIFFERENTIMAGE,2,winSize, 'c:\temp\2.bmp',type =2
;直接保存为bmp
SAVEDIFFERENTIMAGE,2,winSize, 'c:\temp\2.tif',type =3
;对象图形法-灰度图像
oWindow = OBJ_NEW('IDLgrWindow',dimension = winSize,$
title ='灰度图像')
oView = OBJ_NEW('IDLgrView',viewPlane_Rect = [0,0,winSize])
oModel= OBJ_NEW('IDLgrModel')
oImage= OBJ_NEW('IDLgrImage',DIST(400))
;层次体系与绘制
oModel->ADD,oImage
oView->ADD,oModel
oWindow->SETPROPERTY, graphics_tree = oView
oWindow->DRAW
;
oPrint = oWindow.READ()
oPrint->GETPROPERTY, data = data
HELP,data
;后面保存不写了,与SAVEDIFFERENTIMAGE中tvrd后结果一样;
;对象图形法-伪彩色图像
oWindow1 = OBJ_NEW('IDLgrWindow',dimension = winSize,$
title ='伪彩色图像')
oView1 = OBJ_NEW('IDLgrView',viewPlane_Rect = [0,0,winSize])
oModel1= OBJ_NEW('IDLgrModel')
;颜色表
oPalette = OBJ_NEW('IDLgrPalette')
oPalette.LOADCT,5
oImage1= OBJ_NEW('IDLgrImage',DIST(400),PALETTE = oPalette)
;层次体系与绘制
oModel1->ADD,oImage1
oView1->ADD,oModel1
oWindow1->SETPROPERTY, graphics_tree = oView1
oWindow1->DRAW
;
oPrint = oWindow.READ()
oPrint->GETPROPERTY, data = data
HELP,data
;后面保存不写了,与SAVEDIFFERENTIMAGE中tvrd后结果一样;
END
标签:OBJ,SAVEDIFFERENTIMAGE,绘制,IDL,winSize,type,NEW,图形,data 来源: https://www.cnblogs.com/enviidl/p/16355188.html