InputStream in = new FileInputStream(logo);
long imageLength = in.available();
if (1048576 <= imageLength) {
request.setAttribute("error", "公司图标");
return mapping.getInputForward();
} in.close(); String fileExt = getFormat(logo);获得文件的后缀名
if (null == fileExt) {
request.setAttribute("imageError", "");
return mapping.getInputForward();
} File _file = new File(logo); //读入文件 logo是文件的路径
Image src = javax.imageio.ImageIO.read(_file); //构造Image对象
int width = src.getWidth(null); //得到源图宽
int height = src.getHeight(null); //得到源图长
log.debug("$$$$$$$$$$$$$$$" + new Integer(width));
log.debug("$$$$$$$$$$$$$$$" + new Integer(height));
ImageFilter filter = null;
Graphics g = null;
BufferedImage tag= null;
if (500 < width && 375 < height) {
filter = new ReplicateScaleFilter(500, 375);
// tag = new BufferedImage(500, 375, BufferedImage.TYPE_INT_RGB);
// tag.getGraphics().drawImage(src, 0, 0, 500, 375, null); //绘制缩小后的图 }
FilteredImageSource source = new FilteredImageSource(src.getSource(), filter);
Image newImage = Toolkit.getDefaultToolkit().createImage(source);
String strAbsPath = request.getSession().getServletContext().getRealPath(request.getRequestURI());//获得绝对路径
File file = new File(strAbsPath);
strAbsPath = file.getParentFile().getParent() + File.separator + "temp" + File.separator;
//OutputStream out = new FileOutputStream(strAbsPath + "temp." + fileExt); //生成零时路径
File files = new File(strAbsPath);
javax.imageio.ImageIO.write(newImage, fileExt, files);
log.debug("&&&&&&&&&&&&&&" + strAbsPath); InputStream in2 = new FileInputStream(strAbsPath + "temp." + fileExt);
byte[] b = new byte[in2.available()]; in2.read(b);
in2.close();
ep.setLogo(b);
ep.setLogoFormat(fileExt);怎么把生成的Image对象写入零时路径
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货