在WEB页面单幅显示多普勒雷达图像并叠加极圈、极径、市县边界的JSP例子:
(GIF动画显示及直接从.tar.gz中读取源数据的例子略)
01
<%
@
page pageEncoding=
"GB2312"
%>
02
<%
@
page contentType=
"image/jpeg; charset=gb2312"
%>
03
<% request.setCharacterEncoding
(
"GB2312"
)
; %>
04
05
<%
@
page
import
=
"
06
cma.gmb.doppler.*,
07
java.awt.*,
08
java.awt.image.*,
09
com.sun.image.codec.jpeg.*,
10
java.lang.*,
11
java.io.*"
%>
12
13
<%
14
//需要以后台方式用到图形设备
15
System.setProperty
(
"java.awt.headless"
,
"true"
)
;
16
//页面不缓存
17
response.setHeader
(
"Pragma"
,
"no-cache"
)
;
18
response.setHeader
(
"Cache-Control"
,
"no-store"
)
;
19
response.setHeader
(
"Expires"
,
"0"
)
;
20
21
out.clear
()
;
22
23
//获得页面传递的参数
24
String fileString = request.getParameter
(
"f"
)
;
25
26
SymbologyImage symbologyImage =
new
SymbologyImage
()
;
27
boolean
ok = symbologyImage.loadFromFile
(
fileString
)
;
28
if
(
ok
) {
29
BufferedImage image =
new
BufferedImage
(
640
,
480
, BufferedImage.TYPE_3BYTE_BGR
)
;
30
Graphics2D g = image.createGraphics
()
;
31
//以下两行改进线条的锯齿
32
RenderingHints renderHints =
new
RenderingHints
(
RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON
)
;
33
g.setRenderingHints
(
renderHints
)
;
34
double
z =
1.0
;
35
g.setClip
(
0
,
0
,
480
,
480
)
;
36
if
(
null
!= symbologyImage.radialImage
[
0
] ) {
//Radial产品
37
symbologyImage.radialImage
[
0
]
.draw
(
z, g,
new
Point
(
240
,
240
))
;
//画图
38
symbologyImage.radialImage
[
0
]
.drawBackground
(
z, g,
new
Point
(
240
,
240
)
, true,
30.0
,
true
)
;
//极圈极径
39
g.setClip
(
480
,
0
,
160
,
480
)
;
//剪切区域
40
symbologyImage.radialImage
[
0
]
.drawInformation
(
g,
new
Point
(
480
,
0
))
;
//信息区域
41
}
42
else if
(
null
!= symbologyImage.rasterImage
[
0
] ) {
//Raster产品
43
symbologyImage.rasterImage
[
0
]
.draw
(
z, g,
new
Point
(
240
,
240
))
;
//画图
44
symbologyImage.rasterImage
[
0
]
.drawBackground
(
z, g,
new
Point
(
240
,
240
)
, true,
30.0
,
true
)
;
//极圈极径
45
g.setClip
(
480
,
0
,
160
,
480
)
;
//剪切区域
46
symbologyImage.rasterImage
[
0
]
.drawInformation
(
g,
new
Point
(
480
,
0
))
;
//信息区域
47
}
48
g.dispose
()
;
//图形设备生效
49
50
//获得浏览器的输出流
51
ServletOutputStream sos = response.getOutputStream
()
;
52
//JPEG编码器
53
JPEGImageEncoder encoder1 = JPEGCodec.createJPEGEncoder
(
sos
)
;
54
55
//改进图片质量
56
JPEGEncodeParam param1 = encoder1.getDefaultJPEGEncodeParam
(
image
)
;
57
param1.setQuality
(
1.0f
,
false
)
;
58
encoder1.setJPEGEncodeParam
(
param1
)
;
59
60
//输出到浏览器
61
encoder1.encode
(
image
)
;
62
}
63
64
%>