java图片处理 文字水印 图片水印 缩放 补白
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* @author Eric Xu
*
*/
public final class ImageUtils {
/**
* 图片水印
* @param pressImg 水印图片
* @param targetImg 目标图片
* @param x 修正值 默认在中间
* @param y 修正值 默认在中间
* @param alpha 透明度
*/
public final static void pressImage(String pressImg, String targetImg, int x, int y, float alpha) {
try {
File img = new File(targetImg);
Image src = ImageIO.read(img);
int wideth = src.getWidth(null);
int height = src.getHeight(null);
BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.drawImage(src, 0, 0, wideth, height, null);
//水印文件
Image src_biao = ImageIO.read(new File(pressImg));
int wideth_biao = src_biao.getWidth(null);
int height_biao = src_biao.getHeight(null);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha));
g.drawImage(src_biao, (wideth - wideth_biao) / 2, (height - height_biao) / 2, wideth_biao, height_biao, null);
//水印文件结束
g.dispose();
ImageIO.write((BufferedImage) image, "jpg", img);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 文字水印
* @param pressText 水印文字
* @param targetImg 目标图片
* @param fontName 字体名称
* @param fontStyle 字体样式
* @param color 字体颜色
* @param fontSize 字体大小
* @param x 修正值
* @param y 修正值
* @param alpha 透明度
*/
public static void pressText(String pressText, String targetImg, String fontName, int fontStyle, Color color, int fontSize, int x, int y, float alpha) {
try {
File img = new File(targetI
相关文档:
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
package chape7;
/**
* 檢查參數的有效性
* 當編寫方法或者構造器時,應該考慮他的參數有什麽限制 應該吧這些限制寫在文檔中,並且在這個方法的開頭 ......
如题!解决的方法是增加一个虚背景。之后把虚背景增加到原来的Frame上。由于repaint()到paint()中间涉及到update(),所以解决问题的
关键是在重写update(),在这个方法中实现虚背景的添加~~
@Override
public void update(Graphics g)
{
if(offScreenImage == null)
......
java exception 解决方案 - 我的异常网|异常|exception 791 - java.lang.NoSuchMethodError 792 - RuntimeException 793 - org.hibernate.exception.SQLGrammarException 794 - Internal Error 795 - 自定义异常 796 - org.dom4j.DocumentException 797 - java.net.SocketException 798 - Exception对象 799 - SQLE ......
笔试的时候想不起来怎么写了。留个代码作纪念
package common;
import java.io.*;
import java.util.ArrayList;
public class IOTest {
public static void main (String args[]) {
ReadDate();
WriteDate();
}
/**
* 读取数据
*/
public static void ReadDate() {
......