国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

慕課網(wǎng)_《Java實(shí)現(xiàn)圖片水印》學(xué)習(xí)總結(jié)

levius / 2300人閱讀

摘要:時(shí)間年月日星期五說(shuō)明本文部分內(nèi)容均來(lái)自慕課網(wǎng)。慕課網(wǎng)教學(xué)源碼無(wú)學(xué)習(xí)源碼第一章課程簡(jiǎn)介引言通過(guò)一個(gè)項(xiàng)目案例的講解,如何在應(yīng)用中實(shí)現(xiàn)圖片水印的添加。

時(shí)間:2017年07月21日星期五
說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com
教學(xué)源碼:無(wú)
學(xué)習(xí)源碼:https://github.com/zccodere/s...

第一章:課程簡(jiǎn)介 1-1 引言

通過(guò)一個(gè)項(xiàng)目案例的講解,如何在JavaWeb應(yīng)用中實(shí)現(xiàn)圖片水印的添加。

1-2 課程內(nèi)容

課程內(nèi)容

1.Java圖片水印實(shí)現(xiàn)思路
2.課程項(xiàng)目案例介紹
    框架
    實(shí)現(xiàn)方式
    結(jié)果演示
3.課程案例詳解
    實(shí)現(xiàn)圖片添加單個(gè)文字水印
    實(shí)現(xiàn)圖片添加單個(gè)圖片水印
    實(shí)現(xiàn)圖片添加多個(gè)文字水印
    實(shí)現(xiàn)圖片添加多個(gè)圖片水印
    實(shí)現(xiàn)多圖片批量添加水印
4.課程總結(jié)
1-3 課程目標(biāo)

目標(biāo)

1.了解Java圖片水印實(shí)現(xiàn)思路
2.掌握文字水印和圖片水印的思路
3.掌握多圖片批量水印的實(shí)現(xiàn)
第二章:實(shí)現(xiàn)原理 2-1 實(shí)現(xiàn)思路

實(shí)現(xiàn)思路

1.創(chuàng)建緩存圖片對(duì)象
2.創(chuàng)建Java繪圖工具對(duì)象
3.使用繪圖工具對(duì)象將原圖繪制到緩存圖片對(duì)象
4.使用繪圖工具將水印(文字/圖片)繪制到緩存圖片對(duì)象
5.創(chuàng)建圖像編碼工具類
6.使用圖片編碼工具類,輸出緩存圖像到目標(biāo)圖片文件
2-2 實(shí)用工具類

實(shí)用工具類

1.BufferedImage:圖片緩存類
2.Graphics2D:對(duì)平面2D圖片進(jìn)行操作
3.JPEGImageEncoder:對(duì)圖片文件進(jìn)行編碼處理并輸出到磁盤文件中
第三章:案例介紹 3-1 案例演示

項(xiàng)目案例

基于Strutus2框架的JavaWeb應(yīng)用程序,允許一次上傳多個(gè)圖片,應(yīng)用默認(rèn)為上傳圖片添加水印,并將原圖與添加水印圖片對(duì)比展示。

說(shuō)明

個(gè)人學(xué)習(xí)時(shí),均使用SpringBoot框架相關(guān)技術(shù)

結(jié)果演示

默認(rèn)首頁(yè)

點(diǎn)擊瀏覽并選中圖片

點(diǎn)擊上傳,結(jié)果如下

第四章:添加單個(gè)文字水印 4-1 搭建項(xiàng)目

創(chuàng)建名為watermark的maven項(xiàng)目POM文件如下


    4.0.0

    com.myimooc
    watermark
    0.0.1-SNAPSHOT
    jar

    watermark
    http://maven.apache.org

    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.1.RELEASE
         
    

    
        UTF-8
        UTF-8
    

    
        
            org.springframework.boot
            spring-boot-starter
        

        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-freemarker
        

        
            commons-io
            commons-io
            2.5
        

        
        
            net.coobird
            thumbnailator
            0.4.8
        

    

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.8
                    1.8
                
            
        
    

編寫配置類和啟動(dòng)類,完成后項(xiàng)目結(jié)構(gòu)如下

4-2 編寫頁(yè)面

代碼演示:



上傳文件



    

圖片上傳

請(qǐng)上傳圖片

4-3 編寫控制器類

代碼演示:

package com.myimooc.watermark.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.myimooc.watermark.domain.PicInfo;
import com.myimooc.watermark.service.MarkService;
import com.myimooc.watermark.service.UploadService;

/**
 * WatermarkController 控制類
 * 
 * @author ZhangCheng on 2017-07-21
 *
 */
@Controller
public class WatermarkController {

    private static Logger logger = LoggerFactory.getLogger(WatermarkController.class);

    @Autowired
    private UploadService uploadService;

    @Autowired
    private MarkService markService;

    /***
     * 單圖片上傳
     * 
     * @param image
     * @param request
     * @return
     */
    @PostMapping("/watermark")
    public ModelAndView watermark(MultipartFile image, HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/watermark");
        PicInfo picInfo = new PicInfo();

        String uploadPath = "static/images/";
        String realUploadPath = getClass().getClassLoader().getResource(uploadPath).getPath();

        logger.info("上傳相對(duì)目錄:{}", uploadPath);
        logger.info("上傳絕對(duì)目錄:{}", uploadPath);

        String imageURL = uploadService.uploadImage(image, uploadPath, realUploadPath);

        File imageFile = new File(realUploadPath + image.getOriginalFilename());

        String logoImageURL = markService.watermake(imageFile, image.getOriginalFilename(), uploadPath, realUploadPath);

        picInfo.setImageURL(imageURL);
        picInfo.setLogoImageURL(logoImageURL);
        mav.addObject("picInfo", picInfo);

        return mav;
    }

    /**
     * 圖片批量上傳
     * 
     * @param image
     * @param request
     * @return
     */
    @PostMapping("/morewatermark")
    public ModelAndView morewatermark(List image, HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/morewatermark");

        String uploadPath = "static/images/";
        String realUploadPath = getClass().getClassLoader().getResource(uploadPath).getPath();

        logger.info("上傳相對(duì)目錄:{}", uploadPath);
        logger.info("上傳絕對(duì)目錄:{}", realUploadPath);

        if (image != null && image.size() > 0) {
            List picInfoList = new ArrayList();
            for (MultipartFile imageFileTemp : image) {
                if(imageFileTemp == null || imageFileTemp.getSize() < 1){
                    continue;
                }
                PicInfo picInfo = new PicInfo();
                String imageURL = uploadService.uploadImage(imageFileTemp, uploadPath, realUploadPath);
                File imageFile = new File(realUploadPath + imageFileTemp.getOriginalFilename());
                String logoImageURL = markService.watermake(imageFile, imageFileTemp.getOriginalFilename(), uploadPath,
                        realUploadPath);
                picInfo.setImageURL(imageURL);
                picInfo.setLogoImageURL(logoImageURL);
                picInfoList.add(picInfo);
            }
            mav.addObject("picInfoList", picInfoList);
        }
        return mav;
    }
}
4-4 編寫水印接口

代碼演示:

package com.myimooc.watermark.service;

import java.awt.Color;
import java.awt.Font;
import java.io.File;

/**
 * 圖片水印服務(wù)類
 * @author ZhangCheng on 2017-07-21
 *
 */
public interface MarkService {
    
    /** 水印文字內(nèi)容 */
    public static final String MARK_TEXT = "妙手空空";
    /** 水印文字類型 */
    public static final String FONT_NAME = "微軟雅黑";
    /** 水印文字樣式 */
    public static final int FONT_STYLE = Font.BOLD;
    /** 水印文字大小 */
    public static final int FONT_SIZE= 120;// 單位:像素
    /** 水印文字顏色 */
    public static final Color FONT_COLOR= Color.BLACK;
    /** 水印文字位置X軸 */
    public static final int X = 10;
    /** 水印文字位置Y軸 */
    public static final int Y = 10;
    /** 水印文字透明度*/
    public static final float ALPHA = 0.3F;
    
    /** 水印圖片*/
    public static final String LOGO = "logo.png";
    
    /**
     * 功能:將傳入的圖片添加水印并保存到服務(wù)器中
     * @param file
     * @param uploadPath
     * @param realUploadPath
     * @return 添加水印后圖片的URL相對(duì)地址
     */
    String watermake(File imageFile,String imageFileName,String uploadPath,String realUploadPath);
    
}
4-5 添加單個(gè)文字水印

代碼演示

package com.myimooc.watermark.service;

import java.awt.AlphaComposite;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.imageio.ImageIO;

import org.springframework.stereotype.Service;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

/**
 * 圖片水印服務(wù)類,添加文字水印
 * @author ZhangCheng on 2017-07-21
 *
 */
//@Service
@SuppressWarnings("unused")
public class TextMarkServiceImpl implements MarkService {

    @Override
    public String watermake(File imageFile,String imageFileName, String uploadPath, String realUploadPath) {
        
        String logoFileName = "logo_" + imageFileName;
        OutputStream os = null;
        
        try {
            Image image = ImageIO.read(imageFile);
            int width = image.getWidth(null);// 原圖寬度
            int height = image.getHeight(null);// 原圖高度
            
            // 創(chuàng)建圖片緩存對(duì)象
            BufferedImage bufferedImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
            // 創(chuàng)建繪繪圖工具對(duì)象
            Graphics2D g = bufferedImage.createGraphics();
            // 使用繪圖工具將原圖繪制到緩存圖片對(duì)象
            g.drawImage(image, 0, 0, width,height,null);
            
            // 設(shè)置水印文字字體信息
            g.setFont(new Font(FONT_NAME,FONT_STYLE,FONT_SIZE));
            // 設(shè)置水印文字顏色
            g.setColor(FONT_COLOR);
            
            int markWidth = FONT_SIZE * getTextLength(MARK_TEXT);
            int markHeight = FONT_SIZE;
            
            // 水印的高度和寬度之差
            int widthDiff = width - markWidth;
            int heightDiff = height - markHeight;
            
            int x = X;
            int y = Y;
            
            // 判斷設(shè)置的值是否大于圖片大小
            if(x > widthDiff){
                x = widthDiff;
            }
            if(y > heightDiff){
                y =heightDiff;
            }
            
            // 設(shè)置水印文字透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, ALPHA));
            
            // 添加水印
            g.drawString(MARK_TEXT, x, y + FONT_SIZE);
            
            g.dispose();
            
            os = new FileOutputStream(realUploadPath + "/" + logoFileName);
            JPEGImageEncoder en = JPEGCodec.createJPEGEncoder(os);
            en.encode(bufferedImage);
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        
        return uploadPath + "/" + logoFileName;
    }
    
    /**
     * 功能:獲取文本長(zhǎng)度。漢字為1:1,英文和數(shù)字為2:1
     */
    private 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;
    }
}
第五章:添加單個(gè)圖片水印 5-1 圖片水印添加

代碼演示:

package com.myimooc.watermark.service;

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.imageio.ImageIO;

import org.springframework.stereotype.Service;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

/**
 * 圖片水印服務(wù)類,添加圖片水印
 * @author ZhangCheng on 2017-07-22
 *
 */
//@Service
@SuppressWarnings("unused")
public class ImageMarkServiceImpl implements MarkService {

    @Override
    public String watermake(File imageFile, String imageFileName, String uploadPath, String realUploadPath) {
        
        String logoFileName = "logo_" + imageFileName;
        OutputStream os = null;
        
        // 圖片地址
        String logoPath = realUploadPath + "/" + LOGO;
        
        try {
            Image image = ImageIO.read(imageFile);
            int width = image.getWidth(null);// 原圖寬度
            int height = image.getHeight(null);// 原圖高度
            
            // 創(chuàng)建圖片緩存對(duì)象
            BufferedImage bufferedImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
            // 創(chuàng)建繪繪圖工具對(duì)象
            Graphics2D g = bufferedImage.createGraphics();
            // 使用繪圖工具將原圖繪制到緩存圖片對(duì)象
            g.drawImage(image, 0, 0, width,height,null);
            
            // 讀取Logo圖片
            File logo = new File(logoPath);
            Image imageLogo = ImageIO.read(logo);
            
            // 獲取Logo圖片的寬度和高度
            int markWidth = imageLogo.getWidth(null);
            int markHeight = imageLogo.getHeight(null);
            
            // 原圖和Logo圖片的高度和寬度之差
            int widthDiff = width - markWidth;
            int heightDiff = height - markHeight;
            
            int x = X;
            int y = Y;
            
            // 判斷設(shè)置的值是否大于圖片大小
            if(x > widthDiff){
                x = widthDiff;
            }
            if(y > heightDiff){
                y =heightDiff;
            }
            
            // 設(shè)置水印透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, ALPHA));
            
            // 添加水印
            g.drawImage(imageLogo, x, y, null);
            
            g.dispose();
            
            os = new FileOutputStream(realUploadPath + "/" + logoFileName);
            JPEGImageEncoder en = JPEGCodec.createJPEGEncoder(os);
            en.encode(bufferedImage);
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        
        return uploadPath + "/" + logoFileName;
        
    }

}
第六章:添加多個(gè)文字水印 6-1 添加多個(gè)文字水印

代碼演示:

package com.myimooc.watermark.service;

import java.awt.AlphaComposite;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.imageio.ImageIO;

import org.springframework.stereotype.Service;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

/**
 * 圖片水印服務(wù)類,添加多個(gè)文字水印
 * @author ZhangCheng on 2017-07-22
 *
 */
//@Service
@SuppressWarnings("unused")
public class MoreTextMarkServiceImpl implements MarkService {

    @Override
    public String watermake(File imageFile, String imageFileName, String uploadPath, String realUploadPath) {
        String logoFileName = "logo_" + imageFileName;
        OutputStream os = null;
        
        try {
            Image image = ImageIO.read(imageFile);
            int width = image.getWidth(null);// 原圖寬度
            int height = image.getHeight(null);// 原圖高度
            
            // 創(chuàng)建圖片緩存對(duì)象
            BufferedImage bufferedImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
            // 創(chuàng)建繪繪圖工具對(duì)象
            Graphics2D g = bufferedImage.createGraphics();
            // 使用繪圖工具將原圖繪制到緩存圖片對(duì)象
            g.drawImage(image, 0, 0, width,height,null);
            
            // 設(shè)置水印文字字體信息
            g.setFont(new Font(FONT_NAME,FONT_STYLE,FONT_SIZE));
            // 設(shè)置水印文字顏色
            g.setColor(FONT_COLOR);
            
            int markWidth = FONT_SIZE * getTextLength(MARK_TEXT);
            int markHeight = FONT_SIZE;
            
            // 設(shè)置水印透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, ALPHA));
            
            // 旋轉(zhuǎn)圖片
            g.rotate(Math.toRadians(30), bufferedImage.getWidth()/2, bufferedImage.getHeight()/2);
            
            int x = -width / 2;
            int y = -height / 2;
            
            int xmove = 200;// 水印之間的間隔
            int ymove = 200;// 水印之間的間隔
            
            // 循環(huán)添加
            while (x < width * 1.5){
                y = -height / 2;
                while(y < height * 1.5){
                    g.drawString(MARK_TEXT, x, y);
                    
                    y += markHeight + ymove;
                }
                x += markWidth + xmove;
            }
            
            g.dispose();
            
            os = new FileOutputStream(realUploadPath + "/" + logoFileName);
            JPEGImageEncoder en = JPEGCodec.createJPEGEncoder(os);
            en.encode(bufferedImage);
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        
        return uploadPath + "/" + logoFileName;
    }
    
    /**
     * 功能:獲取文本長(zhǎng)度。漢字為1:1,英文和數(shù)字為2:1
     */
    private 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;
    }

}
第七章:添加多個(gè)圖片水印 7-1 添加多個(gè)圖片水印

代碼演示:

package com.myimooc.watermark.service;

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.imageio.ImageIO;

import org.springframework.stereotype.Service;

import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;

/**
 * 圖片水印服務(wù)類,添加多個(gè)圖片水印
 * @author ZhangCheng on 2017-07-22
 *
 */
@Service
public class MoreImageMarkServiceImpl implements MarkService {

    @Override
    public String watermake(File imageFile, String imageFileName, String uploadPath, String realUploadPath) {
        
        String logoFileName = "logo_" + imageFileName;
        OutputStream os = null;
        
        try {
            Image image = ImageIO.read(imageFile);
            int width = image.getWidth(null);// 原圖寬度
            int height = image.getHeight(null);// 原圖高度
            
            // 創(chuàng)建圖片緩存對(duì)象
            BufferedImage bufferedImage = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
            // 創(chuàng)建繪繪圖工具對(duì)象
            Graphics2D g = bufferedImage.createGraphics();
            // 使用繪圖工具將原圖繪制到緩存圖片對(duì)象
            g.drawImage(image, 0, 0, width,height,null);
            
            // 圖片地址
            String logoPath = realUploadPath + "/" + LOGO;
            
            // 讀取Logo圖片
            File logo = new File(logoPath);
            Image imageLogo = ImageIO.read(logo);
            
            // Logo圖片的寬度和高度
            int markWidth = imageLogo.getWidth(null);
            int markHeight = imageLogo.getHeight(null);
            
            // 設(shè)置水印透明度
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, ALPHA));
            
            // 旋轉(zhuǎn)圖片
            g.rotate(Math.toRadians(30), bufferedImage.getWidth()/2, bufferedImage.getHeight()/2);
            
            int x = -width / 2;
            int y = -height / 2;
            
            int xmove = 200;// 水印之間的間隔
            int ymove = 200;// 水印之間的間隔
            
            // 循環(huán)添加
            while (x < width * 1.5){
                y = -height / 2;
                while(y < height * 1.5){
                    // 添加水印
                    g.drawImage(imageLogo, x, y, null);
                    y += markHeight + ymove;
                }
                x += markWidth + xmove;
            }
            
            g.dispose();
            
            os = new FileOutputStream(realUploadPath + "/" + logoFileName);
            JPEGImageEncoder en = JPEGCodec.createJPEGEncoder(os);
            en.encode(bufferedImage);
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        
        return uploadPath + "/" + logoFileName;
        
    }

}
第八章:批量添加圖片水印 8-1 批量添加圖片水印

代碼演示

1.編寫moreupload.html



上傳文件



    

圖片批量上傳

請(qǐng)上傳圖片






2.修改WatermarkController類

package com.myimooc.watermark.controller;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.myimooc.watermark.domain.PicInfo;
import com.myimooc.watermark.service.MarkService;
import com.myimooc.watermark.service.UploadService;

/**
 * WatermarkController 控制類
 * 
 * @author ZhangCheng on 2017-07-21
 *
 */
@Controller
public class WatermarkController {

    private static Logger logger = LoggerFactory.getLogger(WatermarkController.class);

    @Autowired
    private UploadService uploadService;

    @Autowired
    private MarkService markService;

    /***
     * 單圖片上傳
     * 
     * @param image
     * @param request
     * @return
     */
    @PostMapping("/watermark")
    public ModelAndView watermark(MultipartFile image, HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/watermark");
        PicInfo picInfo = new PicInfo();

        String uploadPath = "static/images/";
        String realUploadPath = getClass().getClassLoader().getResource(uploadPath).getPath();

        logger.info("上傳相對(duì)目錄:{}", uploadPath);
        logger.info("上傳絕對(duì)目錄:{}", uploadPath);

        String imageURL = uploadService.uploadImage(image, uploadPath, realUploadPath);

        File imageFile = new File(realUploadPath + image.getOriginalFilename());

        String logoImageURL = markService.watermake(imageFile, image.getOriginalFilename(), uploadPath, realUploadPath);

        picInfo.setImageURL(imageURL);
        picInfo.setLogoImageURL(logoImageURL);
        mav.addObject("picInfo", picInfo);

        return mav;
    }

    /**
     * 圖片批量上傳
     * 
     * @param image
     * @param request
     * @return
     */
    @PostMapping("/morewatermark")
    public ModelAndView morewatermark(List image, HttpServletRequest request) {
        ModelAndView mav = new ModelAndView("/morewatermark");

        String uploadPath = "static/images/";
        String realUploadPath = getClass().getClassLoader().getResource(uploadPath).getPath();

        logger.info("上傳相對(duì)目錄:{}", uploadPath);
        logger.info("上傳絕對(duì)目錄:{}", realUploadPath);

        if (image != null && image.size() > 0) {
            List picInfoList = new ArrayList();
            for (MultipartFile imageFileTemp : image) {
                if(imageFileTemp == null || imageFileTemp.getSize() < 1){
                    continue;
                }
                PicInfo picInfo = new PicInfo();
                String imageURL = uploadService.uploadImage(imageFileTemp, uploadPath, realUploadPath);
                File imageFile = new File(realUploadPath + imageFileTemp.getOriginalFilename());
                String logoImageURL = markService.watermake(imageFile, imageFileTemp.getOriginalFilename(), uploadPath,
                        realUploadPath);
                picInfo.setImageURL(imageURL);
                picInfo.setLogoImageURL(logoImageURL);
                picInfoList.add(picInfo);
            }
            mav.addObject("picInfoList", picInfoList);
        }
        return mav;
    }
}

3.編寫morewatermark.html



處理結(jié)果




    

操作結(jié)果

[#list picInfoList as item] [/#list]

4.效果展示

訪問(wèn)圖片批量上傳頁(yè)

選擇文件

點(diǎn)擊上傳圖片,結(jié)果如下

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/67449.html

相關(guān)文章

  • 課網(wǎng)_Java圖片驗(yàn)證碼》學(xué)習(xí)總結(jié)

    時(shí)間:2017年07月09日星期日說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com教學(xué)源碼:無(wú)學(xué)習(xí)源碼:https://github.com/zccodere/s... 第一章:概述 1-1 課程概述 主要內(nèi)容 驗(yàn)證碼歷史 課程內(nèi)容 不同方案對(duì)比 設(shè)計(jì)與實(shí)現(xiàn) 總結(jié) 1-2 驗(yàn)證碼歷史 驗(yàn)證碼歷史 無(wú)驗(yàn)證碼:垃圾騷擾 Luis von Ahn:Captcha 不斷...

    haitiancoder 評(píng)論0 收藏0
  • 課網(wǎng)_Java實(shí)現(xiàn)圖片等比例縮略圖》學(xué)習(xí)總結(jié)

    摘要:時(shí)間年月日星期六說(shuō)明本文部分內(nèi)容均來(lái)自慕課網(wǎng)。可以更加專注于業(yè)務(wù)邏輯開發(fā),縮短項(xiàng)目開發(fā)周期,提高項(xiàng)目開發(fā)速度。 時(shí)間:2017年07月15日星期六說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com教學(xué)源碼:無(wú)學(xué)習(xí)源碼:https://github.com/zccodere/s... 第一章:課程介紹 1-1 課程介紹 在用戶進(jìn)行信息概略瀏覽的時(shí)候,提供縮...

    raledong 評(píng)論0 收藏0
  • 課網(wǎng)_Java生成二維碼》學(xué)習(xí)總結(jié)

    摘要:時(shí)間年月日星期五說(shuō)明本文部分內(nèi)容均來(lái)自慕課網(wǎng)。線性堆疊式二維碼示意圖矩陣式二維碼在一個(gè)矩形空間通過(guò)黑白像素在矩陣中的不同分布進(jìn)行編碼。 時(shí)間:2017年06月23日星期五說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com教學(xué)示例源碼:無(wú)個(gè)人學(xué)習(xí)源碼:https://github.com/zccodere/s... 第一章:二維碼的概念 1-1 二維碼概述...

    QLQ 評(píng)論0 收藏0
  • 課網(wǎng)_Java實(shí)現(xiàn)Base64加密》學(xué)習(xí)總結(jié)

    摘要:時(shí)間年月日星期一說(shuō)明本文部分內(nèi)容均來(lái)自慕課網(wǎng)。多用于網(wǎng)絡(luò)加密。散列函數(shù)函數(shù)或消息摘要函數(shù)主要作用散列函數(shù)用來(lái)驗(yàn)證數(shù)據(jù)的完整性。 時(shí)間:2017年4月10日星期一說(shuō)明:本文部分內(nèi)容均來(lái)自慕課網(wǎng)。@慕課網(wǎng):http://www.imooc.com教學(xué)示例源碼:https://github.com/zccodere/s...個(gè)人學(xué)習(xí)源碼:https://github.com/zccodere...

    verano 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<