将一张大图片切割成100*100的图片.
用了batik包,可以从这里下载:http://apache.justdn.org/xml/batik/
import org.apache.batik.apps.rasterizer.DestinationType;
import org.apache.batik.apps.rasterizer.SVGConverter;
import javax.imageio.ImageIO;
import java.io.File;
import java.awt.*;
import java.awt.image.BufferedImage;
public class ImageTiler {
private
static final String BASE_DIR = “jpg/”;
private
static final int TILE_WIDTH = 100;
private
static final int TILE_HEIGHT = 100;
public
static void main(String[] args) throws Exception {
// create the tiles
String[][] sources = { { “0/0.jpg”, “0″ },{”0/1.jpg”, “1″} };
for (int i = 0; i < sources.length; i++) {
String[] source = sources[i];
BufferedImage bi = ImageIO.read(new File(BASE_DIR +
source[0]));
int columns = bi.getWidth() / TILE_WIDTH;
int rows = bi.getHeight() / TILE_HEIGHT;
for (int x = 0; x < columns; x++) {
for (int y = 0; y < rows; y++) {
BufferedImage img = new BufferedImage(TILE_WIDTH,
TILE_HEIGHT,
bi.getType());
Graphics2D newGraphics = (Graphics2D) img.getGraphics();
newGraphics.drawImage(bi, 0, 0, TILE_WIDTH, TILE_HEIGHT,
TILE_WIDTH * x, TILE_HEIGHT * y,
TILE_WIDTH * x + TILE_WIDTH,
TILE_HEIGHT * y + TILE_HEIGHT,
null);
ImageIO.write(img, “jpg”, new File(BASE_DIR + “0/” +
“x” + x + “y” + y + “z” + source[1] + “.jpg”));
}
}
}
}
}
<img id=”img1″ src=”img/photo/p01.jpg”>
<script language=javascript>
if(window.screen.width == 800 && window.screen.height ==
600){
document.getElementById(”img1″).width=”480″;
document.getElementById(”img1″).height=”360″;
} else if(window.screen.width == 1024&&
window.screen.height == 768){
document.getElementById(”img1″).width=”640″;
document.getElementById(”img1″).height=”480″;
}
</script>
Tags: javascript, 分辨率, 图像大小, 开放代码
//新闻rss
//jnuzyx.2006.09.20
//需要JDOM1.0
//需要数据库链接类
package rss;
import java.io.FileOutputStream;
import java.util.Date;
import java.text.SimpleDateFormat;
import org.jdom.Attribute;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import org.jdom.output.Format;
import org.jdom.CDATA;
import java.sql.*;
import *.*Pool;
public class news
{
//
public
static void rssnews(String dir) throws Exception {
Element root = new Element(”rss”);
root.setAttribute(new Attribute(”version”, “2.0″));
Document doc = new
Document(root);
//将根元素植入
Element channel = new Element(”channel”);
root.addContent(channel);
Element Ntitle = new Element(”title”);
Ntitle.addContent(”暨南大学图书馆新闻订阅”);
channel.addContent(Ntitle);
Element Nlink = new Element(”link”);
Nlink.addContent(”http://lib.jnu.edu.cn/“);
channel.addContent(Nlink);
Element Ndescription = new Element(”description”);
Ndescription.addContent(”暨南大学图书馆新闻订阅”);
channel.addContent(Ndescription);
Element Nlanguage = new Element(”language”);
Nlanguage.addContent(”zh-cn”);
channel.addContent(Nlanguage);
Element Ncopyright = new Element(”copyright”);
Ncopyright.addContent(”Copyright 2006 暨南大学图书馆. All Rights
Reserved.”);
channel.addContent(Ncopyright);
Element NwebMaster = new Element(”webMaster”);
NwebMaster.addContent(”暨南大学图书馆”);
channel.addContent(NwebMaster);
Element NpubDate = new Element(”pubDate”);
java.util.Date now=new java.util.Date();
NpubDate.addContent(FormatRssDate(now));
channel.addContent(NpubDate);
Element NlastBuildDate = new Element(”lastBuildDate”);
NlastBuildDate.addContent(FormatRssDate(now));
channel.addContent(NlastBuildDate);
Element Ngenerator = new Element(”generator”);
Ngenerator.addContent(”JNULRSS 1.0(beta)”);
channel.addContent(Ngenerator);
//读入数据库数据
//*.*Pool pool = new ****;
ResultSet rs = pool.getRs(”$sql 语句$”);
//增加ITEM
String strContent;
while(rs.next()){
Element student = new
Element(”item”);//生成元素
student.addContent(new
Element(”title”).addContent(rs.getString(”*”)));
student.addContent(new Element(”link”).addContent(”$url$”)));
student.addContent(new
Element(”author”).addContent(”jnuzyx”));
student.addContent(new
Element(”category”).addContent(”暨南大学图书馆新闻订阅”));
student.addContent(new
Element(”pubdate”).addContent(FormatRssDate($date$)));
if(rs.getString(”$content$”)!=null)
{
strContent =
rs.getString(”$content$”).substring(0, 320)+”….”;
}
else
{
strContent = “请点击查看全文….”;
}
student.addContent(new Element(”description”).addContent(new
CDATA(strContent)));
channel.addContent(student);
}
//关闭
if(rs!=null)
{
rs.close();
}
rs = null;
//输出
try{
XMLOutputter XMLOut = new
XMLOutputter(Format.getPrettyFormat());
XMLOut.output(doc, new FileOutputStream(dir + “news.xml”));
}catch (java.io.IOException e) {
e.printStackTrace();
}
}
public
static String FormatRssDate(Date dt) {
SimpleDateFormat RssFmtDt=new SimpleDateFormat(”EEE, dd MM yyyy
HH:mm:ss z”);
return RssFmtDt.format(dt).toString();
}
}