资源简介
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+Access登陆界面
- javaweb登陆注册界面
- java web房屋出租系统项目
- 学生成绩管理系统 java源码 以及项目
- 数字时钟java源码
- mchange-commons-java-0.2.15.jar
-
ob
jectOrientedProgrammingwithJava.pdf - java项目实战适合初学者
- 数字图像处理java版源代码
- Java 、Android实现MP4裁剪功能
- java实现RSA算法的大整数编程----实现对
- SHA1或MD5算法获取文件摘要值(JAVA)
- javaWeb激活邮箱验证资料
- javaWeb前后台交互
- oracle+javaweb 电影管理系统
- 《轻量级Java EE企业应用实战第5版》光
- LWJGL-2.90
- javax.servlet的jar包
- 图书租借系统 javaGUI程序
- jsp+mysql+mvc模式管理系统
- 在线投票系统模块设计报告
- java图书馆简易管理系统
- Java远程控制源代码
- mvc模式画圆JAVA实现
- Java点对点语音实时聊天
- JAVA实现找回密码功能详解。
- java文本编辑器 仿windows记事本
- FineReport报表API源代码报表调用
- Thinking in Java(第四版)源代码
- java的hill算法
评论
共有 条评论