java实现缩略图和抓屏幕
来源:才华咖 本文已影响1.02W人
来源:才华咖 本文已影响1.02W人
在全球范围内,SUN公司的Java技术培训和认证不仅是Java开发技术领域最权威的认证,同时也是开发类认证中很重要的一种.以下是小编整理的关于java实现缩略图和抓屏幕,希望大家认真阅读!
import ainer;
import nsion;
import hics2D;
import e;
import aTracker;
import angle;
import eringHints;
import t;
import kit;
import eredImage;
import eredOutputStream;
import ;
import OutputStream;
import eIO;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
/**
*
* 纯java API实现图片处理
*
Title:ImageChangeSize
*
Description:
*
Copyright: Copyright (c) 2010
*
Company:
* @author
* @version 1.0.0
*/
public class ImageChangeSize
{
public static void main ( String [] args )
throws InterruptedException
{
//测试生成缩略图
createThumbnail("c:555.gif", 200, 200, 100, "c:uuuu.jpg");
//测试捕捉屏幕,每隔一秒捕获一次
String path = "c:screen";
int i = 0;
for ( ;; )
{
i++;
String filepath = path + i + ".jpg";
snatchScreen(filepath);
entThread()p(2000);
}
}
/**
* 处理图片,改变起大小,可进行缩略和放大
* @param filename 源文件名称
* @param thumbWidth 处理后宽度
* @param thumbHeight 处理后高度
* @param quality 品质 最高100,最小0
* @param outFilename 输出文件名称
*/
public static void createThumbnail ( String filename, int thumbWidth, int thumbHeight, int quality, String outFilename )
{
Image image = efaultToolkit()mage(filename);
MediaTracker mediaTracker = new MediaTracker(new Container());
mage(image, 0);
try
{
ForID(0);
double thumbRatio = (double) thumbWidth / (double) thumbHeight;
int imageWidth = idth(null);
int imageHeight = eight(null);
double imageRatio = (double) imageWidth / (double) imageHeight;
if ( thumbRatio < imageRatio )
{
thumbHeight = (int) ( thumbWidth / imageRatio );
}
else
{
thumbWidth = (int) ( thumbHeight * imageRatio );
}
BufferedImage thumbImage = new BufferedImage(thumbWidth,
thumbHeight, _INT_RGB);
Graphics2D graphics2D = teGraphics();
enderingHint(_INTERPOLATION, E_INTERPOLATION_BILINEAR);
Image(image, 0, 0, thumbWidth, thumbHeight, null);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFilename));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
quality = (0, (quality, 100));
uality((float) quality / 100.0f, false);
encoder.setJPEGEncodeParam(param);
de(thumbImage);
e();
}
catch ( Exception e )
{
tStackTrace();
}
}
/**
* 抓取电脑屏幕
* @param path
*/
public static void snatchScreen ( String path )
{
Robot robot;
try
{
robot = new Robot();
Dimension d = efaultToolkit()creenSize();
Rectangle rect = new Rectangle(0, 0, h, ht);
BufferedImage image = teScreenCapture(rect);
e(image, "jpg", new File(path));
}
catch ( Exception e )
{
tln("Failed to snatch screen ... ");
tStackTrace();
}
}
}
使用JavaScript实现Java的List功能
使用matlab和Java作闭合多边形图例题讲解
深入理解JS实现快速排序和去重javascript技巧
Java开发策略模式的简单应用实现方法
java上传图片的缩放的方法
有关JAVA和JAVAC命令详细介绍
Javascript和Java语言间的异同比较
Java语言的特点和实现机制
经典Java面试题之Java中Char类型的运算
JAVA和JAVAC命令行大全
Java 2.1 java基本类型的转换和运算符
Java网上考试系统的设计和实现
Java程序运行后如何才能把窗口显示在屏幕中间
javaScript实现可缩放显示区效果代码
实现鼠标画图的Java程序
Java4安卓开发教程之java的变量
Java与JavaScript的区别
政治历史和现实表现
Java import以及Java类的搜索路径
如何做到超大屏幕上重现《开国大典》
JavaScript与java语言有何区别
Java 队列实现原理及简单实现代码
Java认证考试知识点:JavaSE6的新功能
用javascript实现图片模糊到清晰载效果指南
JavaScript与java语言有何不同
JavaScript与Java的区别
Java面试题Java写一个折半查找
java与JavaScript语言有何不同
java实现缩略图和抓屏幕
java使用ConcurrentHashMap和计数器实现锁的方法
java与javascript之间json格式数据互转详解
JavaScript-JavaScript数据结构和算法之图和图算法,
Java语言的现状和发展前景
计算机二级JAVA考试构建JAVA程序2017
Win7将图片设置为缩略图步骤
Java认证考试知识点:Java时间类的函数
在Java中执行JavaScript代码
sun认证java程序员须知Java日志框架
Java入门教程:如何使用一个Java
JavaScript与java语言的区别