/**
* 打水印 Imagename_biao是水印文件 ImgName是原图
* @param Imagename_biao
* @param ImgName
*/
public static void imgYin(String Imagename_biao, String ImgName) {
//System.out.println("11111111111111111111111111111111 inin");
FileImageOutputStream out=null;
File _file=null;
BufferedImage image=null;
File _filebiao=null;
try {
_file = new File(ImgName);
Image src = ImageIO.read(_file);
int wideth = src.getWidth(null);
int height = src.getHeight(null); //宽大于300才打水印
if (wideth > 300) {
image = new BufferedImage(wideth, height,
BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
g.drawImage(src, 0, 0, wideth, height, null);
// g.drawImage(src.getScaledInstance(wideth,
// height,Image.SCALE_SMOOTH), 0, 0,wideth, height, null); // 水印文件
_filebiao = new File(Imagename_biao);
Image src_biao = ImageIO.read(_filebiao);
int wideth_biao = src_biao.getWidth(null);
int height_biao = src_biao.getHeight(null);
// 水印文件显示在中央
g.drawImage(src_biao, (int) (0.5 * (wideth - wideth_biao)),
(int) (0.5 * (height - height_biao)), wideth_biao,
height_biao, null);
// g.drawImage(src_biao.getScaledInstance(wideth_biao,
// height_biao,Image.SCALE_SMOOTH), (int)(0.5*(wideth
// -wideth_biao)) , (int)(0.5*(height -height_biao)),
// wideth_biao,
// height_biao, null);
// 水印文件在原图片文件的位置,原图片文件的右下角为wideth-0,height-0
g.dispose();
// FileOutputStream out = new FileOutputStream(ImgName);
// JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
// JPEGEncodeParam param =
// encoder.getDefaultJPEGEncodeParam(image);
// param.setQuality(0.9f, false); //不压缩图像fals
// encoder.setJPEGEncodeParam(param);
// encoder.encode(image);
// out.flush();
// out.close(); // ImageIO.write(image, "jpg", new File(ImgName)); Iterator<ImageWriter> iter = ImageIO
.getImageWritersByFormatName("jpg");
if (iter.hasNext()) {
ImageWriter writer = iter.next();
ImageWriteParam param = writer.getDefaultWriteParam(); param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); //MODE_COPY_FROM_METADATA ,MODE_EXPLICIT
param.setCompressionQuality(0.9f);
//System.out.println("Quality:"+1.0);
out = new FileImageOutputStream(
new File(ImgName));
writer.setOutput(out);
// writer.write(bi);
writer.write(null, new IIOImage(image, null, null), param);
out.close();
writer.dispose(); } } } catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}finally{ if(out!=null){
try
{
out.close();
} catch (Exception e) {
//e.printStackTrace();
}
}
}
}

宝贝网址:

打水印 Imagename_biao是水印文件 ImgName是原图的更多相关文章

  1. JAVA实用案例之水印开发

    写在最前面 上周零零碎碎花了一周的时间研究水印的开发,现在终于写了个入门级的Demo,做下笔记同时分享出来供大家参考. Demo是在我上次写的 JAVA实用案例之文件导入导出(POI方式) 框架基础上 ...

  2. JAVA实用案例之图片水印开发

    写在最前面 上周零零碎碎花了一周的时间研究水印的开发,现在终于写了个入门级的Demo,做下笔记同时分享出来供大家参考. Demo是在我上次写的 JAVA实用案例之文件导入导出(POI方式) 框架基础上 ...

  3. 逆天通用水印支持Winform,WPF,Web,WP,Win10。支持位置选择(9个位置 ==》[X])

    常用技能:http://www.cnblogs.com/dunitian/p/4822808.html#skill 逆天博客:http://dnt.dkil.net 逆天通用水印扩展篇~新增剪贴板系列 ...

  4. 不错.net图片水印类

    using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Draw ...

  5. 应用DEV第三方界面控件制作批量添加水印程序

    本次应用DevExpress和C#语言制作了一个批量添加水印的程序,看界面效果图: 界面中既可以进行文字水印添加,也可以图片水印添加,同时还可以对水印的位置进行设置,比较实用! 文字水印的具体添加情况 ...

  6. ThinkPHP图片上传

    ThinkPHP是国内比较流行的轻量级的PHP框架,它在国内流行的一个最主要的因素在于它的说明文档非常健全完善,以及它源码内的注释都是中文的,方便于英语能力较差的程序员学习. 图片上传在网站里是很常用 ...

  7. thinkphp达到UploadFile.class.php图片上传功能

    片上传在站点里是非经常常使用的功能.ThinkPHP里也有自带的图片上传类(UploadFile.class.php) 和图片模型类(Image.class.php).方便于我们去实现图片上传功能,以 ...

  8. .net为图片添加水印(转) jpg png和gif格式

    .net为图片添加水印(转) jpg png和gif格式 .net为图片添加水印(转) jpg png和gif格式,转自csdn的hyde82,现在跟大家一起来分享下: 利 用.net中System. ...

  9. 上传图片(示列分析) $_FILES

    新建一个think_photo数据库,库里用sql CREATE TABLE IF NOT EXISTS `think_photo` ( `id` ) NOT NULL AUTO_INCREMENT, ...

随机推荐

  1. NET中的Memcached.ClientLibrary使用详解

    memcached在windows下的下载与安装 下载地址:http://pan.baidu.com/s/1yVILw       提取密码:5gx9 官方网站:http://memcached.or ...

  2. Java内存区域

    1.运行时数据区域 java虚拟机在执行java程序的过程中会将它管理的内存区域分为若干个不同的数据区域.这些区域有各自的服务对象,创建以及销毁时间,有的内存区域随着虚拟机的启动和关闭而创建和销毁,有 ...

  3. Struts2中Action由自己与由Spring管理的区别

    struts2单独使用时action由struts2自己负责创建:与spring集成时,action实例由spring负责创建. 这导致在两种情况下struts.xml配置文件的略微差异.   假如: ...

  4. /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc

    /etc/profile./etc/bashrc.~/.bash_profile.~/.bashrc很容易混淆,他们之间有什么区别?它们的作用到底是什么?/etc/profile: 用来设置系统环境参 ...

  5. java GC的优化

    参考网摘: http://www.360doc.com/content/13/0305/10/15643_269388816.shtml

  6. Nuget 常用命令

    Update-Package -ProjectName 'NLog' -Reinstall 主题 about_NuGet 简短说明 提供有关 NuGet 程序包管理器命令的信息. 详细说明 本主题介绍 ...

  7. SQLAlchemy query with OR/AND/like common filters

    http://www.leeladharan.com/sqlalchemy-query-with-or-and-like-common-filters Some of the most common ...

  8. 黑马程序员_ Objective-c 之Foundation笔记(二)

    NSArray NSArray的创建 NSArray *array = [NSArray arrayWithObject:@“jack”]   创建单个元素 NSArray *array3 = [NS ...

  9. QT总结第3篇:如何在QT中添加.lib,.dll还有.h文件

    因为我在工作的过程中,使用的是第三方提供的库,但是如何将这些库添加到QT的工程中,是个问题,让我恼火了很久,怎么弄都是错的. 下面,我会对这个问题,进行叙述,希望其他人第一次遇到这种问题的时候,可以轻 ...

  10. hibernate配置文件hibernate.cfg.xml的详细解释

    <!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式-->                 <?x ...