资源简介
Java实现的JPEG算法,只有一个文件,但是支持调整压缩质量,方便学习图像编码
代码片段和文件信息
// Version 1.0a
// Copyright (C) 1998 James R. Weeks and BioElectroMech.
// Visit BioElectroMech at www.obrador.com. Email James@obrador.com.
// See license.txt for details about the allowed used of this software.
// This software is based in part on the work of the Independent JPEG Group.
// See IJGreadme.txt for details about the Independent JPEG Group‘s license.
// This encoder is inspired by the Java Jpeg encoder by Florian Raemy
// studwww.eurecom.fr/~raemy.
// It borrows a great deal of code and structure from the Independent
// Jpeg Group‘s Jpeg 6a library Copyright Thomas G. Lane.
// See license.txt for details.
import java.applet.applet;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import java.lang.*;
/*
* JpegEncoder - The JPEG main program which performs a jpeg compression of
* an image.
*/
public class JpegEncoder extends frame
{
Thread runner;
BufferedOutputStream outStream;
Image image;
JpegInfo JpegObj;
Huffman Huf;
DCT dct;
int imageHeight imageWidth;
int Quality;
int code;
public static int[] jpegNaturalOrder = {
0 1 8 16 9 2 3 10
17 24 32 25 18 11 4 5
12 19 26 33 40 48 41 34
27 20 13 6 7 14 21 28
35 42 49 56 57 50 43 36
29 22 15 23 30 37 44 51
58 59 52 45 38 31 39 46
53 60 61 54 47 55 62 63
};
public JpegEncoder(Image image int quality OutputStream out)
{
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(image 0);
try {
tracker.waitForID(0);
}
catch (InterruptedException e) {
// Got to do something?
}
/*
* Quality of the image.
* 0 to 100 and from bad image quality high compression to good
* image quality low compression
*/
Quality=quality;
/*
* Getting picture information
* It takes the Width Height and RGB scans of the image.
*/
JpegObj = new JpegInfo(image);
imageHeight=JpegObj.imageHeight;
imageWidth=JpegObj.imageWidth;
outStream = new BufferedOutputStream(out);
dct = new DCT(Quality);
Huf=new Huffman(imageWidthimageHeight);
}
public void setQuality(int quality) {
dct = new DCT(quality);
}
public int getQuality() {
return Quality;
}
public void Compress() {
WriteHeaders(outStream);
WriteCompressedData(outStream);
WriteEOI(outStream);
try {
outStream.flush();
} catch (IOException e) {
System.out.println(“IO Error: “ + e.getMessage());
}
}
public void WriteCompressedData(BufferedOutputStream
- 上一篇:javaweb登陆注册界面
- 下一篇:java+Access登陆界面
相关资源
- 微博系统(Java源码,servlet+jsp),适
- java串口通信全套完整代码-导入eclip
- jsonarray所必需的6个jar包.rar
- 三角网构TIN生成算法,Java语言实现
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
评论
共有 条评论