From 24222aa218513fd969c77df5feb386c9fccd4161 Mon Sep 17 00:00:00 2001
From: 81041 <81041@DESKTOP-025NVD9>
Date: 星期二, 15 一月 2019 16:01:47 +0800
Subject: [PATCH] 手机端上传加水印
---
gx_tieta/src/com/fgkj/actions/MyFileAction.java | 172 ++++++++++++++++++++++++++++++++++++++++++-
gx_tieta/src/com/fgkj/dto/BattInf.java | 11 ++
gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/actions/MyFileAction.class | 0
gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/dto/BattInf.class | 0
4 files changed, 178 insertions(+), 5 deletions(-)
diff --git a/gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/actions/MyFileAction.class b/gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/actions/MyFileAction.class
index 455aa9c..824af13 100644
--- a/gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/actions/MyFileAction.class
+++ b/gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/actions/MyFileAction.class
Binary files differ
diff --git a/gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/dto/BattInf.class b/gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/dto/BattInf.class
index 429521c..4f5d229 100644
--- a/gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/dto/BattInf.class
+++ b/gx_tieta/WebRoot/WEB-INF/classes/com/fgkj/dto/BattInf.class
Binary files differ
diff --git a/gx_tieta/src/com/fgkj/actions/MyFileAction.java b/gx_tieta/src/com/fgkj/actions/MyFileAction.java
index 8e6bd5f..f6b4188 100644
--- a/gx_tieta/src/com/fgkj/actions/MyFileAction.java
+++ b/gx_tieta/src/com/fgkj/actions/MyFileAction.java
@@ -1,16 +1,27 @@
package com.fgkj.actions;
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
+import com.fgkj.dao.DAOHelper;
import com.fgkj.dto.BattInf;
+import com.fgkj.dto.BattMap_information;
import com.fgkj.dto.MyFile;
import com.fgkj.dto.ServiceModel;
import com.google.gson.Gson;
@@ -274,8 +285,151 @@
}
}
+ //涓婁紶鏈烘埧瑙嗛鎺ュ彛(鎵嬫満绔�)
+ public String uploadStationFile_mobile(){
+ BattInf binf = getGson().fromJson(json, BattInf.class);
+ String fileRoot = "stationsrc";
+ ServiceModel model = new ServiceModel();
+ boolean isSuccess = false;
+ String loadpath = ActionUtil.getSession().getServletContext().getRealPath("/");
+ String str = new File(loadpath).getParentFile().getAbsolutePath(); //鑾峰彇鏈嶅姟鍣ㄦ墍鍦ㄧ殑缁濆璺緞
+ String root = str+"/"+fileRoot+"/"+binf.getStationId()+"/"+binf.getVideoOrImage()+"/"; // 涓婁紶璺緞
+ for(int i=0;i<file.length && binf != null;i++){
+ String filePath = root+fileFileName[i];
+ createFilefolderIFNotExist(filePath);
+ if(binf.getVideoOrImage().equals("image")) {
+ GraphicsFile(binf.getBinfmation(), file[i], filePath);
+ }else {
+ copyFile(file[i], filePath);
+ }
+ isSuccess = true;
+ }
+ if(isSuccess){
+ model.setCode(1);
+ model.setMsg("涓婁紶鎴愬姛");
+ }else{
+ model.setCode(0);
+ model.setMsg("涓婁紶澶辫触");
+ }
+ result = tojson(model);
+ return SUCCESS;
+ }
+ //灏嗚幏鍙栧埌寰楀浘鐗囧姞姘村嵃
+ public static void GraphicsFile(Object obj, File file,String newImagePath) {
+ //InputStream is = null;
+ OutputStream os = null;
+ BattMap_information binfmation=(BattMap_information) obj;
+ try {
+ // 1銆佹簮鍥剧墖
+ java.awt.Image srcImg = ImageIO.read(file);
+ //System.out.println(srcImg.);
+ BufferedImage buffImg = new BufferedImage(srcImg.getWidth(null),srcImg.getHeight(null), BufferedImage.TYPE_INT_RGB);
+ // 2銆佸緱鍒扮敾绗斿璞�
+ Graphics2D g = buffImg.createGraphics();
+ // 3銆佽缃绾挎鐨勯敮榻跨姸杈圭紭澶勭悊
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+ g.drawImage(srcImg.getScaledInstance(srcImg.getWidth(null), srcImg.getHeight(null), java.awt.Image.SCALE_SMOOTH), 0, 0, null);
+ // 4銆佽缃按鍗版棆杞�
+ /*if (null != degree) {
+ //System.out.println("buffImg.getWidth():"+buffImg.getWidth()+" buffImg.getHeight():"+buffImg.getHeight());
+ g.rotate(Math.toRadians(degree), buffImg.getWidth()/10,buffImg.getHeight() /10);
+ }*/
+ // 5銆佽缃按鍗版枃瀛楅鑹�
+ g.setColor(new Color(255,0,0));//榛樿绾㈣壊
+ int font_size= buffImg.getHeight() /35;
+ // 6銆佽缃按鍗版枃瀛桭ont
+ g.setFont(new java.awt.Font("瀹嬩綋", java.awt.Font.BOLD,font_size));
+ // 7銆佽缃按鍗版枃瀛楅�忔槑搴�
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.9f));
+ // 8銆佺涓�鍙傛暟->璁剧疆鐨勫唴瀹癸紝鍚庨潰涓や釜鍙傛暟->鏂囧瓧鍦ㄥ浘鐗囦笂鐨勫潗鏍囦綅缃�(x,y)
+ //璁剧疆缁忓害
+ g.drawString("缁忓害:"+binfmation.getLongitude(), 0 , font_size);
+ //璁剧疆绾害
+ g.drawString("绾害:"+binfmation.getLatitude(), 0 , font_size*2);
+ //璁剧疆鍦板潃
+ String address="鍦板潃:"+binfmation.getAddress();
+ int address_size=getTextLength(address)*font_size;
+ if(address_size<buffImg.getWidth()) {
+ g.drawString(address, 0 , font_size*(3));
+ }else {
+ for (int i = 0; i <=address_size/buffImg.getWidth(); i++) {
+ if(i==0) {
+ g.drawString(address.substring( 0,buffImg.getWidth()/font_size*(i+1)), 0 , font_size*(2+i+1));
+ }else {
+ if(i==address_size/buffImg.getWidth()) {
+ g.drawString(address.substring( buffImg.getWidth()/font_size*(i),(address.length()) ), 0 , font_size*(5+i+1));
+ }else{
+ g.drawString(address.substring( buffImg.getWidth()/font_size*(i),buffImg.getWidth()/font_size*(i+1) ), 0 , font_size*(5+i+1));
+ }
+
+ }
+ }
+ }
+
+
+ //璁剧疆鏃堕棿
+ g.drawString("鏃堕棿:"+DAOHelper.sdf.format(new Date()), 0 , font_size*4);
+ //璁剧疆鏈烘埧id
+ g.drawString("鏈烘埧ID:"+binfmation.getStationId(), 0 , font_size*5);
+ //璁剧疆澶囨敞
+ String note="澶囨敞:"+binfmation.getStationName();
+ int note_size=getTextLength(note)*font_size;
+ //System.out.println(getTextLength(binfmation.getStationName()));
+ //System.out.println("font_size:"+font_size+" note_size:"+note_size+" buffImg.getWidth():"+buffImg.getWidth());
+ if(note_size<buffImg.getWidth()) {
+ g.drawString(note, 0 , font_size*6);
+ }
+ for (int i = 0; i <=note_size/buffImg.getWidth(); i++) {
+ if(i==0) {
+ g.drawString(note.substring( 0,buffImg.getWidth()/font_size*(i+1) ), 0 , font_size*(5+i+1));
+ }else {
+ if(i==note_size/buffImg.getWidth()) {
+ g.drawString(note.substring( buffImg.getWidth()/font_size*(i),(note.length()) ), 0 , font_size*(5+i+1));
+ }else{
+ g.drawString(note.substring( buffImg.getWidth()/font_size*(i),buffImg.getWidth()/font_size*(i+1) ), 0 , font_size*(5+i+1));
+ }
+
+ }
+ }
+ // 9銆侀噴鏀捐祫婧�
+ g.dispose();
+ // 10銆佺敓鎴愬浘鐗�
+ os = new FileOutputStream(newImagePath);
+ //System.out.println(os);
+ ImageIO.write(buffImg, "JPG", os);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ /* try {
+ if (null != is)
+ is.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }*/
+ try {
+ if (null != os)
+ os.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+ //璁$畻姘村嵃鏂囨湰闀垮害
+ //1銆佷腑鏂囬暱搴﹀嵆鏂囨湰闀垮害 2銆佽嫳鏂囬暱搴︿负鏂囨湰闀垮害浜屽垎涔嬩竴
+ public static int getTextLength(String text){
+ //姘村嵃鏂囧瓧闀垮害
+ int length = text.length();
-
+ for (int i = 0; i < text.length(); i++) {
+ String s =String.valueOf(text.charAt(i));
+ if (s.getBytes().length>1) {
+ length++;
+ }
+ }
+ length = length%2==0?length/2:length/2+1;
+ return length;
+ }
public void setFilestr(String filestr) {
this.filestr = filestr;
}
@@ -312,11 +466,21 @@
}
public static void main(String[] args) {
- String filePath = "D:/test/a/a.txt";
+ /*String filePath = "D:/test/a/a.txt";
//ActionUtil.createFileRootIFNotExist(filePath);
File file = new File(filePath);
- System.out.println(ActionUtil.tojson(file));
-
+ System.out.println(ActionUtil.tojson(file));*/
+ //GraphicsFile("鎴戞槸椴佹槦浼�","D:\\1.jpg","D:\\2.jpg",0,new Color(255,0,0),"JPG");
+ BattMap_information binfmation=new BattMap_information();
+ binfmation.setStationId("42000001");
+ binfmation.setStationName("骞胯タ鐪�-鐧捐壊-GX鐧捐壊涔愪笟鍘跨珛鏂板皬鍖篧F-BTS璁惧");
+ binfmation.setAddress("鐧捐壊甯備箰涓氬幙绔嬫柊灏忓尯闄勮繎灞呮皯妤间笂");
+ binfmation.setLongitude(106.55);
+ binfmation.setLatitude(24.78);
+ File file=new File("D:\\1.jpg");
+ String filePath = "D:\\2.jpg";
+ //String filename="2.jpg";
+ GraphicsFile(binfmation,file,filePath);
}
}
diff --git a/gx_tieta/src/com/fgkj/dto/BattInf.java b/gx_tieta/src/com/fgkj/dto/BattInf.java
index f017289..7737fc4 100644
--- a/gx_tieta/src/com/fgkj/dto/BattInf.java
+++ b/gx_tieta/src/com/fgkj/dto/BattInf.java
@@ -96,6 +96,8 @@
private float charge_curr_max;//鍏呯數鐢垫祦闃堝��
private String VideoOrImage ;//涓婁紶鏂囦欢鐨勬牸寮�
+
+ private BattMap_information binfmation;//鏈烘埧缁忕含搴︿俊鎭�
public BattInf() {
super();
}
@@ -606,6 +608,12 @@
public void setReal_cap_group1(float real_cap_group1) {
this.real_cap_group1 = real_cap_group1;
}
+ public BattMap_information getBinfmation() {
+ return binfmation;
+ }
+ public void setBinfmation(BattMap_information binfmation) {
+ this.binfmation = binfmation;
+ }
@Override
public String toString() {
return "BattInf [num=" + num + ", StationId=" + StationId + ", StationId_ex=" + StationId_ex + ", StationName="
@@ -633,7 +641,8 @@
+ ", DisCurrMax=" + DisCurrMax + ", SignalName=" + SignalName + ", StartNum=" + StartNum
+ ", Station_install=" + Station_install + ", Size=" + Size + ", page=" + page + ", obj=" + obj
+ ", station_phone=" + station_phone + ", install_user=" + install_user + ", binf_ex=" + binf_ex
- + ", charge_curr_max=" + charge_curr_max + ", VideoOrImage=" + VideoOrImage + "]";
+ + ", charge_curr_max=" + charge_curr_max + ", VideoOrImage=" + VideoOrImage + ", binfmation="
+ + binfmation + "]";
}
--
Gitblit v1.9.1