易截截图软件、单文件、免安装、纯绿色、仅160KB

java 压缩图片 实例

public class ImageSizer {
public static final MediaTracker tracker = new MediaTracker(new Component() {
private static final long serialVersionUID = 1234162663955668507L;
});
/**
* 图片压缩
*
* @param originalFile 原图像
* @param resizedFile 压缩后的图像
* @param width 图像宽
* @param format 图片格式 jpg, png, gif(非动画)
* @throws IOException
*/
public static void resize(File originalFile, File resizedFile, int width, String format) throws IOException {
if (format != null && "gif".equals(format.toLowerCase())) {
resize(originalFile, resizedFile, width, 1);
return;
}
FileInputStream fis = new FileInputStream(originalFile);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
int readLength = -1;
int bufferSize = 1024;
byte bytes[] = new byte[bufferSize];
while ((readLength = fis.read(bytes, 0, bufferSize)) != -1) {
byteStream.write(bytes, 0, readLength);
}
byte[] in = byteStream.toByteArray();
fis.close();
byteStream.close();
Image inputImage = Toolkit.getDefaultToolkit().createImage(in);
waitForImage(inputImage);
int imageWidth = inputImage.getWidth(null);
if (imageWidth < 1) {
throw new IllegalArgumentException("image width " + imageWidth + " is out of range");
}
int imageHeight = inputImage.getHeight(null);
if (imageHeight < 1) {
throw new IllegalArgumentException("image height " + imageHeight + " is out of range");
}
// Create output image.
int height = -1;
double scaleW = (double) imageWidth / (double) width;
double scaleY = (double) imageHeight / (double) height;
if (scaleW >= 0 && s


相关文档:

java实现zip文件压缩,解压

这几天看了网上一些前辈的代码,自己对Java实现zip文件的解压,压缩有一点理解,故写下留着以后参考。
为了处理中文乱码问题,使用ant.jar包。
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
......

Java 连接 SQL Server 2000示例代码

你的SQL Server 2000必须打上SP3的补,然后安装Microsoft的JDBC驱动,将以下三个jar包复制到WebContent\WEB-INF\lib
msbase.jar
mssqlserver.jar
msutil.jar
下面是测试代码,没有报错数据库就能正常连接
 public class DbcTest {
/**
* @param args
*/
public static void main(String[] args) {
Str ......

[转]java抽象类和接口的区别 详细解说

关键字: java抽象类和接口的区别---详细解说
abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制,正是由于这两种机制的存在,才赋予了Java强大的面向对象能力。abstract class和interface之间在对于抽象类定义的支持方面具有很大的相似性,甚至可以相互替换,因此很多开发者在进行抽象类定义时对于 ......

java数据库设计中的14个技巧

 下述十四个技巧,是许多人在大量的数据库分析与设计实践中,逐步总结出来的。对于这些经验的运用,读者不能生帮硬套,死记硬背,而要消化理解,实事求是,灵活掌握。并逐步做到:在应用中发展,在发展中应用。
      1. 原始单据与实体之间的关系
  
      ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号