當前位置:首頁 » 文件管理 » 圖片批量上傳java

圖片批量上傳java

發布時間: 2022-07-22 12:30:54

『壹』 求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

熱點內容
oracle資料庫時間類型 發布:2025-03-22 16:11:07 瀏覽:51
PHP製作 發布:2025-03-22 16:10:05 瀏覽:732
人類語言編譯器 發布:2025-03-22 16:00:19 瀏覽:176
美團編程 發布:2025-03-22 15:50:54 瀏覽:802
禁止地區訪問 發布:2025-03-22 15:48:44 瀏覽:201
ps必須存儲為副本 發布:2025-03-22 15:43:49 瀏覽:112
mac輸出源碼 發布:2025-03-22 15:24:21 瀏覽:119
伺服器固件版本指的什麼 發布:2025-03-22 15:23:34 瀏覽:621
安卓系統怎麼卸載手機應用 發布:2025-03-22 15:22:36 瀏覽:902
直播源碼安裝教程 發布:2025-03-22 15:22:36 瀏覽:677