java生成圖片進(jìn)行套打功能
更新時(shí)間:2018年08月07日 15:16:47 作者:奮斗小牛
這篇文章主要為大家詳細(xì)介紹了java生成圖片進(jìn)行套打功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了java生成圖片進(jìn)行套打的具體代碼,供大家參考,具體內(nèi)容如下
import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.util.Calendar; import javax.imageio.ImageIO; import org.junit.Test; public class imgecreate{ @Test public void graphicsGeneration() { try { int imageWidth = 3507;// 圖片的寬度 int imageHeight = 2480;// 圖片的高度 BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics graphics = image.getGraphics(); graphics.setColor(Color.white); graphics.fillRect(0, 0, imageWidth, imageHeight); graphics.setColor(Color.black); graphics.setFont(new Font("宋體", Font.PLAIN, 70)); String address="山東省飛史蒂夫肯德基首付款艱苦奮斗就勝多負(fù)少的飛電風(fēng)扇"; //為控制字符串過長(zhǎng)換行 graphics.drawString(address.substring(0,13), 985,1416); graphics.drawString(address.substring(13), 985,1484); Calendar now = Calendar.getInstance(); //證書有效期為3年,所以截止日減去1天 now.set(Calendar.DATE, now.get(Calendar.DATE)-1); now.add(Calendar.YEAR, 3);// BufferedImage small = ImageIO.read(new File("D://t.jpg"));//生成的圖片中插入另一張圖片 graphics.drawImage(small, 2524, 943, 385,385, null); graphics.dispose(); createImage("D://test1.jpg", image); }catch(Exception e) { e.printStackTrace(); } } private static void createImage(String fileLocation, BufferedImage image) { try { ImageIO.write(image, "jpeg" , new File(fileLocation)); image.flush(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args){ }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Struts 2 實(shí)現(xiàn)Action的幾種方式
本篇文章主要介紹了Struts 2 實(shí)現(xiàn)Action的幾種方式,Struts 2框架下實(shí)現(xiàn)Action類有三種方式,有興趣的可以了解一下2017-10-10springMVC配置環(huán)境實(shí)現(xiàn)文件上傳和下載
這篇文章主要為大家詳細(xì)介紹了springMVC配置環(huán)境實(shí)現(xiàn)文件上傳和下載的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05SpringBoot?使用?Sa-Token?完成注解鑒權(quán)功能(權(quán)限校驗(yàn))
Sa-Token?是一個(gè)輕量級(jí)?java?權(quán)限認(rèn)證框架,主要解決登錄認(rèn)證、權(quán)限認(rèn)證、單點(diǎn)登錄、OAuth2、微服務(wù)網(wǎng)關(guān)鑒權(quán)?等一系列權(quán)限相關(guān)問題,這篇文章主要介紹了SpringBoot使用Sa-Token完成注解鑒權(quán)功能,需要的朋友可以參考下2023-05-05