欢迎来到天天文库
浏览记录
ID:15606937
大小:178.50 KB
页数:11页
时间:2018-08-04
《java图像分割方法集合》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、importjava.awt.*;importjavax.swing.*;classImageTestextendsJFrame{publicImageTest(){setSize(300,300);setVisible(true);}publicImage[]splitImage(Stringfile,introws,intcols){System.out.println("Test");Imaget=newImageIcon(file).getImage();Image[]result=newIm
2、age[rows*cols];intw=t.getWidth(this)/cols;inth=t.getHeight(this)/rows;try{for(inti=0;i3、Test");}}catch(Exceptione){}returnresult;}}classTestextendsJFrame{publicTest(){setSize(300,300);setVisible(true);}publicvoidpaint(Graphicsg){ImageTesttt=newImageTest();Image[]image=tt.splitImage("1.gif",5,5);g.drawImage(image[0],0,0,this);}publicstaticv4、oidmain(String[]args){newTest();}}―――――――――――――――――――――――――――――――――――将一个大图像分割成几个小图像的代码//分割图像的方法。importjavax.swing.*;importjava.awt.*;importjava.awt.image.*;importjava.net.URL;importjava.io.File;importjava.util.Hashtable;publicclassChenWin504extendsJAppl5、et{Imageim;MediaTrackerme;Imageimag[];publicstaticHashtablecache;publicvoidinit(){URLur=ChenWin504.class.getResource("images/ima");imag=newImage[10];System.out.println(ur);im=getToolkit().getImage("images/ima/jumptojavastrip.png");me=newMediaTracker(thi6、s);me.addImage(im,0);try{me.waitForID(0);}catch(Exceptione){}DemoImages();for(inti=0;i<10;i++){imag[i]=(Image)cache.get("jumptojavastrip-"+i+".png");if(imag[i]==null)System.out.println("null");}}publicvoidpaint(Graphicsg){intx=5;inty=100;g.drawImage(im,7、5,0,null);for(inti=0;i<10;i++){g.drawImage(imag[i],x,y,null);x+=100;if(x>300){x=5;y+=100;}}}publicvoidDemoImages(){URLurl=ChenWin504.class.getResource("images/ima");Filedir=newFile(url.getFile());if(dir!=null&&dir.isDirectory()){Stringlist[]=dir.list();8、System.out.println(list.length);cache=newHashtable(list.length);for(inti=0;i
3、Test");}}catch(Exceptione){}returnresult;}}classTestextendsJFrame{publicTest(){setSize(300,300);setVisible(true);}publicvoidpaint(Graphicsg){ImageTesttt=newImageTest();Image[]image=tt.splitImage("1.gif",5,5);g.drawImage(image[0],0,0,this);}publicstaticv
4、oidmain(String[]args){newTest();}}―――――――――――――――――――――――――――――――――――将一个大图像分割成几个小图像的代码//分割图像的方法。importjavax.swing.*;importjava.awt.*;importjava.awt.image.*;importjava.net.URL;importjava.io.File;importjava.util.Hashtable;publicclassChenWin504extendsJAppl
5、et{Imageim;MediaTrackerme;Imageimag[];publicstaticHashtablecache;publicvoidinit(){URLur=ChenWin504.class.getResource("images/ima");imag=newImage[10];System.out.println(ur);im=getToolkit().getImage("images/ima/jumptojavastrip.png");me=newMediaTracker(thi
6、s);me.addImage(im,0);try{me.waitForID(0);}catch(Exceptione){}DemoImages();for(inti=0;i<10;i++){imag[i]=(Image)cache.get("jumptojavastrip-"+i+".png");if(imag[i]==null)System.out.println("null");}}publicvoidpaint(Graphicsg){intx=5;inty=100;g.drawImage(im,
7、5,0,null);for(inti=0;i<10;i++){g.drawImage(imag[i],x,y,null);x+=100;if(x>300){x=5;y+=100;}}}publicvoidDemoImages(){URLurl=ChenWin504.class.getResource("images/ima");Filedir=newFile(url.getFile());if(dir!=null&&dir.isDirectory()){Stringlist[]=dir.list();
8、System.out.println(list.length);cache=newHashtable(list.length);for(inti=0;i
此文档下载收益归作者所有