java图片处理 文字水印 图片水印 缩放 补白
转自 http://www.javaeye.com/topic/309457
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)
相关文档:
JAVA,List,Map,Set,容器
Collection
├List
│├LinkedList
│├ArrayList
│└Vector
│ └Stack
└Set
Map
├Hashtable
├HashMap
└WeakHashMap
Collection接口
Collection是最基本的集合接口,一个Collection代表一组Object,即Collection的元素(Elements)。一些 Collection允许相同的元素而 ......
作为java程序员,中文的乱码问题会经常碰到。过去的一个项目,我碰到了各种类型的java乱码问题。先分享给大家:
1:网页Post请求,提交后,显示提交结果,乱码。
首先确定数据库的编码方式。这里我发现,如果数据库的编码不是UTF-8,Post请求也可以保证回显正确,但是有一个地方要注意。
如html中:
(1)<i ......
xml文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel switchTime="20080101000101" k="1.07" n="6" s="55" channelId="0404" channelName="xxxx.xxxx.xxx.cn"/>
<channel switchTime="20080301010101" k="1.07" n="6" s="55" channelId="0405" channelName="xxx ......
Java中Inputstream与Reader的区别
Reader支持16位的Unicode字符输出,InputStream支持8位的字符输出。
Reader和InputStream分别是I/O库提供的两套平行独立的等级机构,
InputStream、OutputStream是用来处理8位元的流,
Reader、Writer是用来处理16位元的流。
而在JAVA语言中,byte类型是8位的,char类型是1 ......