package com.lindows.util;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.image.codec.jpeg.JPEGCodec;
public class ImageProcess {
/**
* @param processImg
* 水印文件,最好用gif或者png可以支持透明
* @param oldImg
* 原始图片文件
* @param newImg
* 生成图片文件
* @param x
* 水印的横坐标
* @param y
* 水印的纵坐标
*/
public static final void processImg(String processImg, String oldImg,
String newImg, int x, int y) {
try {
// 目标文件
File file = new File(oldImg);
Image oldImage = ImageIO.read(file);
int width = oldImage.getWidth(null);
int height = oldImage.getHeight(null);
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
g.drawImage(oldImage, 0, 0, width, height, null);
// 水印文件
File file2 = new File(processImg);
Image addImg = ImageIO.read(file2);
int width1 = addImg.getWidth(null);
int height1 = addImg.getHeight(null);
g.drawImage(addImg, width - width1 - x, height - height1 - y,
width1, height1, null);
// g.drawImage(addImg, (width - width1) / 2 - x, (height - height1)/
// 2 - y, null);
// 水印结束
g.dispose();
FileOutputStream out = new FileOutputStream(newImg);
JPEGImageEncoder encorder = JPEGCodec.createJPEGEncoder(out);
encorder.encode(image);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// 测试方法
ImageProcess.processImg("G:/png.png", "G:/1.png", "G:/3.jpg", 0, 0);
}
}
分享到:
相关推荐
Java图像处理类库 Java Image Filters
基于java的开发源码-图像处理类库 Java Image Filters.zip 基于java的开发源码-图像处理类库 Java Image Filters.zip 基于java的开发源码-图像处理类库 Java Image Filters.zip 基于java的开发源码-图像处理类库 ...
Java Image Processing Recipes With OpenCV and JVM 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
java imageProcess 图像处理程序模板,java imageProcess 图像处理程序模板
Java图像处理类库 Java Image Filters.7z
免积分下载地址:https://xiaoding.pipipan.com/fs/1927055-243488486 更多免积分电子书:https://xiaoding.pipipan.com/dir/1927055-27864699-a6b34f/ 关注我的简书主页,随时获取最新免费电子书:...
Java Image Filters是一款基于Java的图像处理类库,特别是在图像滤镜特效方面,Java Image Filters简直就是强大到天衣无缝。它几乎提供了PS上大部分的图像特效。比如反色特效、图像扭曲、水波和纹理等效果。
java源码:Java图像处理类库 Java Image Filters.zip
Display image in an array, interactive by keyboard and mouse.
这个类可以实现Image到BufferedImage的向下转换,方便各位开发各类需要图像处理的程序。
基于Java的图像处理类库 Java Image Filters.zip
基于java的图像处理类库 Java Image Filters.zip
ImageJ 支持图片格式转换,图片放大缩小等 是一个不错的选择,压缩包中包括库文件,实例类,以及ImageJ的源代码!还有API帮助文档!DOC文档太大.暂不发送
基于Java的实例源码-图像处理类库 Java Image Filters.zip
Java Image Processing Recipes: With OpenCV and JVM English | ISBN: 1484234642 | 2018 | 379 pages | PDF
下面的这个例子示范怎样使用Javax.imageio包来从一个文件、输入流或URL获取图象资源,同时也示范了如何来把Image显示到屏幕上.
NULL 博文链接:https://wuzijingaip.iteye.com/blog/612290
有关Java image的文件获取、显示、像素分解、合成 ,相信对从事java游戏编程的朋友们有所帮助!