当前位置: 技术问答>java相关
请问各位大虾,在Applet中如何缩放图片?
来源: 互联网 发布时间:2015-03-30
本文导语: 同上 | Scale an Image import java.awt.image.*; import java.awt.*; import java.net.*; public class app extends java.applet.Applet { Image source; Image resizedImage; public void init() { MediaTracker media = new...
同上
|
Scale an Image
import java.awt.image.*;
import java.awt.*;
import java.net.*;
public class app extends java.applet.Applet {
Image source;
Image resizedImage;
public void init() {
MediaTracker media = new MediaTracker(this);
// java how-to image for example
source = getImage(getDocumentBase(),"jht.gif");
media.addImage(source,0);
try {
media.waitForID(0);
// scale down, half the original size
ImageFilter replicate =
new ReplicateScaleFilter
(source.getWidth(this)/2, source.getHeight(this)/2);
ImageProducer prod =
new FilteredImageSource(source.getSource(),replicate);
resizedImage = createImage(prod);
media.addImage(resizedImage,1);
media.waitForID(1);
}
catch(InterruptedException e) {}
}
public void paint(Graphics g) {
g.drawImage(source, 10,10,this);
g.drawImage(resizedImage,10, 80,this);
}
}
import java.awt.image.*;
import java.awt.*;
import java.net.*;
public class app extends java.applet.Applet {
Image source;
Image resizedImage;
public void init() {
MediaTracker media = new MediaTracker(this);
// java how-to image for example
source = getImage(getDocumentBase(),"jht.gif");
media.addImage(source,0);
try {
media.waitForID(0);
// scale down, half the original size
ImageFilter replicate =
new ReplicateScaleFilter
(source.getWidth(this)/2, source.getHeight(this)/2);
ImageProducer prod =
new FilteredImageSource(source.getSource(),replicate);
resizedImage = createImage(prod);
media.addImage(resizedImage,1);
media.waitForID(1);
}
catch(InterruptedException e) {}
}
public void paint(Graphics g) {
g.drawImage(source, 10,10,this);
g.drawImage(resizedImage,10, 80,this);
}
}
|
用imagefilter类里的方法
|
java Api中有一个imagefilter的class,(好像是这个名字)你去看看!有这方面的内容!
|
很容易做到啊,简单得很