图片批量上传java
‘壹’ 求java图片批量上传,改小,加水印处理代码,50分相送
//添加水印,filePath 源图片路径, watermark 水印图片路径
public static boolean createMark(String filePath,String watermark) {
ImageIcon imgIcon=new ImageIcon(filePath);
Image theImg =imgIcon.getImage();
ImageIcon waterIcon=new ImageIcon(watermark);
Image waterImg =waterIcon.getImage();
int width=theImg.getWidth(null);
int height= theImg.getHeight(null);
BufferedImage bimage = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB);
Graphics2D g=bimage.createGraphics( );
g.setColor(Color.red);
g.setBackground(Color.white);
g.drawImage(theImg, 0, 0, null );
g.drawImage(waterImg, 100, 100, null );
g.drawString("12233",10,10); //添加文字
g.dispose();
try{
FileOutputStream out=new FileOutputStream(filePath);
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage);
param.setQuality(50f, true);
encoder.encode(bimage, param);
out.close();
}catch(Exception e){ return false; }
return true;
}
‘贰’ java批量上传图片
附件1:
<input name="file1" type="file" size="15" value="">
附件2:
<input name="file2" type="file" size="15" value="">
附件3:
<input name="file3" type="file" size="15" value="">
附件4:
<input name="file4" type="file" size="15" value="">
附件5:
<input name="file5" type="file" size="15" value="">
然后再提交处理的类中逐个处理就可以啦,修改点name属性,看仔细。
‘叁’ java图片批量上传代码
用struts也可以实现 多文件上传
下面是我写的代码,作为参考!
/*文件目录*/
public static String [] fileArray={
"logo.png",
"index.swf",
"OEMInfo.txt",
"favicon.ico"};
/**
* @author Caoshun
* @see 接收并保存文件
* */
public static void receiveAndSaveAllFileByPath(ActionForm form,String rootPath1,String rootPath2){
String fileName="";
//获取表单中的文件资源
Hashtable<Object, Object> files = form.getMultipartRequestHandler().getFileElements();
//遍历文件,并且循环保存
//当前处理文件序号
int file_num=1;
for (Enumeration<Object> e = files.keys(); e.hasMoreElements();) {
/*根据处理的当前文件下标,确定文件名*/
fileName=fileArray[file_num-1];
FormFile file = (FormFile) files.get((String) e.nextElement());
if (file != null && file.getFileSize() > 0) {
try {
//使用formfile.getInputStream()来获取一个文件的输入流进行保存。
//文件名
//String fileName = file.getFileName();
//System.out.println("debug in AddEnterpriceAction.java on line 152 fileName is : "+fileName);
//文件大小
//int fileSize = file.getFileSize();
//文件流
InputStream is = file.getInputStream();
//将输入流保存到文件
//String rootPath = this.servlet.getServletContext().getRealPath("files");
//往cn中写入
File rf = new File(rootPath1);
FileOutputStream fos = null;
fos = new FileOutputStream(new File(rf, fileName));
byte[] b = new byte[10240];
int real = 0;
real = is.read(b);
while (real > 0) {
fos.write(b, 0, real);
real = is.read(b);
}
//往en中写入
File rf2 = new File(rootPath2);
InputStream is2 = file.getInputStream();
FileOutputStream fos2 = null;
fos2 = new FileOutputStream(new File(rf2, fileName));
byte[] b2 = new byte[10240];
int real2 = 0;
real2 = is2.read(b2);
while (real2 > 0) {
fos2.write(b2, 0, real2);
real2 = is2.read(b2);
}
//关闭文件流
fos.close();
is.close();
fos2.close();
is2.close();
} catch (RuntimeException e1) {
e1.printStackTrace();
} catch (Exception ee) {
ee.printStackTrace();
}
file.destroy();
}
file_num++;
}
}
‘肆’ java语言如何实现批量上传照片
使用Java语言实现的批量上传文件,其中使用到了Alanx技术,有需要的可以下载下来看看,希望对您有所帮助!
‘伍’ java批量上传图片的web项目
用jspSmartUpload组件来实现,用jsp+servlet在Servlet里实现的代码:PrintWriter out = response.getWriter(); int count = 0; // 实例化上传控件对象 SmartUpload su = new SmartUpload(); // 初始化操作 su.initialize
‘陆’ java实现文件批量上传是否需要将文件重命名(包括图片,word文档,录音),保存到项目中需要注意哪些
要看情况:
1. 若上传文件直接保存成数据库中的blob字段,那就无所谓文件名了;
2. 若上传文件保存到服务器的某个文件夹中,那么为了避免重名,上传的文件一定要重命名,做法一般是:首先生成一串不会和其他文件相同的名称,例如序列的值、上传时间(精确到毫秒)等;其次,将上传的文件保存到该文件名中;最后,向数据库中记录原上传的文件名、以及生成的文件名。这样,向用户显示的是用户上传的名称,但下载时按数据库中的记录按图索骥即可。
‘柒’ 用java完成图片多张批量上传的功能,还有就是后台的应该怎么处理上传的照片。
Chrome浏览器用小乐图客,可以批量上传图片。 至于上传前压缩,如果是指减小图片尺寸,可以使用小乐图客的美图功能(缩放) 如果是指减小体积(size),那就可以使用小乐图客存图功能(需先下调jpeg品质,建议设置为95,图片质量损失不大)
‘捌’ 用java如何一次性上传多张图片到数据库
你说的这个问题,其实是表的设计问题。
只要在t_b中,设计列为3列即可。
id
,
t_a_id
,
picture
添加多个图片,不过是sql、语句。
最简单的办法,是利用for()循环,如:
for(int
i
=
0;i<图片数;i++){
//你的sql操作语句如。
//insert
图片i
into
t_b..
}
分给偶吧。。
^
^!
‘玖’ java 如何通过Excel批量上传图片
通过jxl.jar
去操作 遍历execl里面的cell然后取出路径值 去用for循环 验证所以路径是否合法 存在文件 都合法存储 不和法 则打印异常
如果不去验证 则无法确认是不是所有文件都上传了
如果是2007的execl、建议你去看看openxml Java操作的话可以用POI