
正文
java大图轮换的代码 java 图片旋转代码
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
求一个用BufferedImage这个改变图片大小的JAVA代码!~!
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class ImageZipUtil {
/**
* 压缩图片文件br
* 先保存原文件,再压缩、上传
*
* @param oldFile
* 要进行压缩的文件全路径
* @param width
* 宽度
* @param height
* 高度
* @param quality
* 质量
* @param smallIcon
* 小图片的后缀
* @return 返回压缩后的文件的全路径
*/
public String zipImageFile(String oldFile, int width, int height,
float quality, String smallIcon) {
if (oldFile == null) {
return null;
}
String newImage = null;
try {
/** 对服务器上的临时文件进行处理 */
Image srcFile = ImageIO.read(new File(oldFile));
int w = srcFile.getWidth(null);
System.out.println(w);
System.out.println(smallIcon);
System.out.println(smallIcon);
int h = srcFile.getHeight(null);
System.out.println(h);
//width = w/4;
//height = h/4;
/** 宽,高设定 */
BufferedImage tag = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(srcFile, 0, 0, width, height, null);
String filePrex = oldFile.substring(0, oldFile.indexOf('.'));
/** 压缩后的文件名 */
newImage = filePrex + smallIcon
+ oldFile.substring(filePrex.length());
/** 压缩之后临时存放位置 */
FileOutputStream out = new FileOutputStream(newImage);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(tag);
/** 压缩质量 */
jep.setQuality(quality, true);
encoder.encode(tag, jep);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return newImage;
}
/**
* 保存文件到服务器临时路径
*
* @param fileName
* @param is
* @return 文件全路径
*/
public String writeFile(String fileName, InputStream is) {
if (fileName == null || fileName.trim().length() == 0) {
return null;
}
try {
/** 首先保存到临时文件 */
FileOutputStream fos = new FileOutputStream(fileName);
byte[] readBytes = new byte[512];// 缓冲大小
int readed = 0;
while ((readed = is.read(readBytes)) 0) {
fos.write(readBytes, 0, readed);
}
fos.close();
is.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return fileName;
}
public static void main(String[] args){
ImageZipUtil u = new ImageZipUtil();
u.zipImageFile("e:/SAM_0006.JPG", 128, 128, 1f, "x2");
}
}
相关问答
Q1: java图片轮换
script language="javascript" src=""/script
script type="text/javascript"
function dk_slideplayer(object,config){
this.obj = object;
this.config = config ? config : {width:"300px",height:"200px",fontsize:"12px",right:"10px",bottom:"10px",time:"5000"};
this.pause = false;
var _this = this;
if(!this.config.right){
this.config.right = "0px"
}
if(!this.config.bottom){
this.config.bottom = "3px"
}
if(this.config.fontsize == "12px" || !this.config.fontsize){
this.size = "12px";
this.height = "21px";
this.right = "6px";
this.bottom = "10px";
}else if(this.config.fontsize == "14px"){
this.size = "14px";
this.height = "23px";
this.right = "6px";
this.bottom = "15px";
}
this.count = jQuery(this.obj + " li").size();
this.n =0;
this.j =0;
var t;
this.factory = function(){
jQuery(this.obj).css({position:"relative",zIndex:"0",margin:"0",padding:"0",width:this.config.width,height:this.config.height,overflow:"hidden"})
jQuery(this.obj).prepend("div style='position:absolute;z-index:20;right:"+this.config.right+";bottom:"+this.config.bottom+"'/div");
jQuery(this.obj + " li").css({width:"100%",height:"100%",overflow:"hidden"}).each(function(i){jQuery(_this.obj + " div").append("a"+(i+1)+"/a")});
jQuery(this.obj + " img").css({border:"none",width:"100%",height:"100%"})
this.resetclass(this.obj + " div a",0);
jQuery(this.obj + " p").each(function(i){
jQuery(this).parent().append(jQuery(this).clone(true));
jQuery(this).html("");
jQuery(this).css({position:"absolute",margin:"0",padding:"0",zIndex:"1",bottom:"0",left:"0",height:_this.height,width:"100%",background:"#000",opacity:"0.4",overflow:"hidden"})
jQuery(this).next().css({position:"absolute",margin:"0",padding:"0",zIndex:"2",bottom:"0",left:"0",height:_this.height,lineHeight:_this.height,textIndent:"5px",width:"100%",textDecoration:"none",fontSize:_this.size,color:"#FFFFFF",background:"none",zIndex:"1",opacity:"1",overflow:"hidden"})
if(i!= 0){jQuery(this).hide().next().hide()}
});
this.slide();
this.addhover();
t = setInterval(this.autoplay,this.config.time);
}
this.slide = function(){
jQuery(this.obj + " div a").mouseover(function(){
_this.j = jQuery(this).text() - 1;
_this.n = _this.j;
if (_this.j = _this.count){return;}
jQuery(_this.obj + " li").hide();
jQuery(_this.obj + " p").hide();
jQuery(_this.obj + " li").eq(_this.j).fadeIn("slow");
jQuery(_this.obj + " li").eq(_this.j).find("p").show();
_this.resetclass(_this.obj + " div a",_this.j);
});
}
this.addhover = function(){
jQuery(this.obj).hover(function(){clearInterval(t);}, function(){t = setInterval(_this.autoplay,_this.config.time)});
}
this.autoplay = function(){
_this.n = _this.n = (_this.count - 1) ? 0 : ++_this.n;
jQuery(_this.obj + " div a").eq(_this.n).trigger('mouseover');
}
this.resetclass =function(obj,i){
jQuery(obj).css({float:"left",marginRight:"3px",width:"15px",height:"14px",lineHeight:"15px",textAlign:"center",fontWeight:"800",fontSize:"12px",color:"#000",background:"#FFFFFF",cursor:"pointer"});
jQuery(obj).eq(i).css({color:"#FFFFFF",background:"#FF7D01",textDecoration:"none"});
}
this.factory();
}
/script
ul class="slideplay" id="pub_slideplay"
lia target="_blank" href="#"img alt="" src="images/downstage/flash1.jpg" /
p/p
/a/li
lia target="_blank" href="#"img alt="" src="images/downstage/flash3.jpg" /
p/p
/a/li
/ul
script type="text/javascript"new dk_slideplayer("#pub_slideplay",{width:"725px",height:"137px",fontsize:"12px",time:"5000"});/script
最后一句话修改图片大小
最后一句话上面 java大图轮换的代码的ul里修改图片路径
可以添加li和删除li来控制图片数量
Q2: 求用Java做播放器的代码和网页上12345自动切换图片的代码
试试这个焦点图切换
有12345数字一起切换
鼠标点一下数字会变换到另一张图片,不点就会自动换
里面有教程和源码
Q3: java代码延迟30秒
setTimeout()在js类中的使用方法
setTimeout (表达式,延时时间)
setTimeout(表达式,交互时间)
延时时间/交互时间是以豪秒为单位的(1000ms=1s)
setTimeout 在执行时,是在载入后延迟指定时间后,去执行一次表达式,仅执行一次
setTimeout 在执行时,它从载入后,每隔指定的时间就执行一次表达式
1,基本用法:
执行一段代码:
var i=0;
setTimeout("i+=1;alert(i)",1000);
执行一个函数:
var i=0;
setTimeout(function(){i+=1;alert(i);},1000);
//注意比较上面的两种方法的不同。
下面再来一个执行函数的:
var i=0;
function test(){
i+=1;
alert(i);
}
setTimeout("test()",1000);
也可以这样:
setTimeout(test,1000);
总结:
setTimeout的原型是这样的:
iTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])
setTimeout有两种形式
setTimeout(code,interval)
setTimeout(func,interval,args)
其中code是一个字符串
func是一个函数.
注意"函数"的意义,是一个表达式,而不是一个语句.
比如你想周期性执行一个函数
function a(){
//...
}
可写为
setTimeout("a()",1000)
或
setTimeout(a,1000)
这里注意第二种形式中,是a,不要写成a(),切记!!!
展开来说,不管你这里写的是什么,如果是一个变量,一定是一个指向某函数的变量;如果是个函数,那它的返回值就 要是个函数
2,用setTimeout实现setInterval的功能
思路很简单,就是在一个函数中调用不停执行自己,有点像递归
var i=0;
function xilou(){
i+=1;
if(i10){alert(i);return;}
setTimeout("xilou()",1000);
//用这个也可以
//setTimeout(xilou,1000);
}
Q4: 如何用java代码实现手动点击图片更换想要换的图片替换
一个图片时你知道,现在只是切换的问题?
给按钮添加一个 ActionListener,在它的 actionPerformed 方法中做你的事情,把 jpanel.setIcon(..) 换张图片。
java大图轮换的代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java 图片旋转代码、java大图轮换的代码的信息别忘了在本站进行查找喔。





