<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'indexjsp' starting page</title>
<script type="text/javascript">
function showPicture(){
var path=documentform1picturePathvalue;
documentgetElementById("img")src=path;
}
</script>
</head>
<body>
<form name="form1" action="PicturServlet" method="post">
<table>
<tr>
<td><img src="" name="img" id="img" height="200px"/></td>
</tr>
<tr>
<td><input type="file" name="picturePath" onchange="showPicture()"/></td>
<td><input type="submit" value="上传"></td>
</tr>
</table>
</form>
</body>
</html>string strFile= "F:\\worddoc ";//注意文件路径
ResponseClear();
ResponseClearHeaders();
ResponseCharset = "GB2312 ";
ResponseContentEncoding =SystemTextEncodingUTF8;
ResponseContentType = "application/msword ";
ResponseWriteFile(strFile);到 >windows有自带视频播放 音频 播放 查看的、是一个空间、你上百度搜搜看、我忘了、很久没弄了、很简单的 传一个路劲就ok、路劲你就使用<input type="file" >获取
把按照规定的比例压缩,然后保存至FTP,列表读取缩略图,单击显示原图。
/压缩方法一(高质量)
@param oldFile 将要压缩的
@param width 压缩宽
@param height 压缩高
@param smallIcon 压缩后,添加的扩展名(在后缀名前添加)
@param quality 压缩质量 范围:<i>00-10</i> 高质量:<i>075</i> 中等质量:<i>05</i> 低质量:<i>025</i>
@param percentage 是否等比压缩 若true宽高比率将将自动调整
/
public static void compressImage(String oldFile, int width, int height, String smallIcon,
float quality, boolean percentage) {
try {
File file = new File(oldFile);
// 验证文件是否存在
if(!fileexists())
throw new FileNotFoundException("找不到原!");
// 获取信息
BufferedImage image = ImageIOread(file);
int orginalWidth = imagegetWidth();
int orginalHeight = imagegetHeight();
// 验证压缩信息
if (width <= 0 || height <= 0 || !Patternmatches("^[1-9]\\d$", StringvalueOf(width))
|| !Patternmatches("^[1-9]\\d$", StringvalueOf(height)))
throw new Exception("压缩后的高宽有误!");
// 等比压缩
if (percentage) {
double rate1 = ((double) orginalWidth) / (double) width + 01;
double rate2 = ((double) orginalHeight) / (double) height + 01;
double rate = rate1 > rate2 rate1 : rate2;
width = (int) (((double) orginalWidth) / rate);
height = (int) (((double) orginalHeight) / rate);
}
// 压缩后的文件名
String filePrex = oldFilesubstring(0, oldFilelastIndexOf(''));
String newImage = filePrex + smallIcon + oldFilesubstring(filePrexlength());
// 压缩文件存放位置
File savedFile = new File(newImage);
// 创建一个新的文件
savedFilecreateNewFile();
// 创建原图像的缩放版本
Image image2 = imagegetScaledInstance(width, height, ImageSCALE_AREA_AVERAGING);
// 创建数据缓冲区图像
BufferedImage bufImage = new BufferedImage(width, height, BufferedImageTYPE_INT_RGB);
// 创建一个Graphics2D
Graphics2D g2 = bufImagecreateGraphics();
// 重绘图像
g2drawImage(image2, 0, 0, width, height, null);
g2dispose();
// 过滤像素矩阵
float[] kernelData = {
-0125f, -0125f, -0125f,
-0125f, 2, -0125f, -0125f,
-0125f, -0125f };
Kernel kernel = new Kernel(3, 3, kernelData);
// 按核数学源图像边缘的像素复制为目标中相应的像素输出像素
ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOpEDGE_NO_OP, null);
// 转换像素
bufImage = cOpfilter(bufImage, null);
FileOutputStream out = new FileOutputStream(savedFile);
JPEGImageEncoder encoder = JPEGCodeccreateJPEGEncoder(out);
JPEGEncodeParam param = encodergetDefaultJPEGEncodeParam(bufImage);
// 设置压缩质量
paramsetQuality(quality, true);
encoderencode(bufImage, param);
outclose();
Systemoutprintln(newImage);
} catch (Exception e) {
eprintStackTrace();
Systemoutprintln("压缩失败!" + egetMessage());
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)