java实现缩略图和抓屏幕
在全球范围内,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();
}
}
}
-
H3C认证无线技术专家考试简介
H3CSWLAN(H3CCertifiedSpecialistForWLAN,H3C认证无线技术专家)认证将帮助您在了解802.11协议族标准和主流WLAN设备及天线的基础上,进一步掌握无线网络勘测与设计,并具备使用H3C无线产品进行应用布署、工程实施和运维指导的能力。H3CSWLAN认证适用的对象包括:各行...
-
2017年计算机应用能力考试题库
计算机系统实现自动维护和诊断的技术。实施维护诊断自动化的主要软件为功能检查程序和自动诊断程序。以下是关于计算机应用能力考试题库,希望大家认真阅读!1、要求:在当前添加一个默认组织结构图:答案:菜单插入→图片→组织结构图。2、要求:将当前幻灯片的...
-
2017年计算机等级考试二级C语言考试试题
C语言强大的移植性(Portability)在此显现。机器语言和汇编语言都不具有移植性,为x86开发的程序,不可能在Alpha,SPARC和ARM等机器上运行。下面是小编整理的关于计算机等级考试二级C语言考试试题,欢迎大家参考!(一)单选题(每题1分,共20分)1.第二代电子计算机所采用的...
-
H3C认证考试指南
关于H3C认证考试H3C认证考试项目为考生提供了检测自己对所学知识掌握的程度,并且能够通过参加考试巩固所学知识,并明确自己的知识薄弱点和以后学习的方向。通过和培训项目对应的考试后可以获得业界认可的国际化的认证证书,并获得更多的就业机会和能力认可。H3C认...