資源簡介
編寫的JAVA類可以進(jìn)行圖片反色處理,圖片的放大和縮小。

代碼片段和文件信息
import?java.awt.image.BufferedImage;
public?class?ImageZoom{
/**
?*?
?*/
private?static?final?long?serialVersionUID?=?1L;
private?ImageZoom()
{}
//圖片按比例縮放
public?static?BufferedImage?createZoomImage(BufferedImage?imagefloat?zoom)
{
return?createZoomImage(imagezoomzoom);
}
//圖片不按比例縮放
public?static?BufferedImage?createZoomImage(BufferedImage?imagefloat?xZoomfloat?yZoom)
{
BufferedImage?createImage=null;
if(image!=null)
{
int?width=0;
int?height=0;
int?forX=0;
int?forY=0;
int?tempZoomStartX=0;
int?tempZoomStartY=0;
int?tempZoomEndX=0;
int?tempZoomEndY=0;
int?rgb=0;
int?imageRGB[]?=?null;
int?imageChangeRGB[]?=?null;
width=(int)(image.getWidth()*xZoom);
height=(int)(image.getHeight()*yZoom);
forX=image.getWidth();
forY=image.getHeight();
imageChangeRGB=new?int[height*width];
imageRGB=new?int[forX*forY];
image.getRGB(0?0?forX?forY?imageRGB?0?forX);
createImage=new?BufferedImage(widthheightBufferedImage.TYPE_INT_RGB);
for(int?y=0;y {
for(int?x=0;x {
tempZoomStartX=(int)(x*xZoom);
tempZoomStartY=(int)(y*yZoom);
tempZoomEndX=(int)((x+1)*xZoom);
tempZoomEndY=(int)((y+1)*yZoom);
rgb=imageRGB[y*forX+x];
for(int?yy=tempZoomStartY;yy {
for(int?xx=tempZoomStartX;xx {
imageChangeRGB[yy*width+xx]=rgb;
}
}
}
}
createImage.setRGB(0?0?width?height?imageChangeRGB?0?width);
imageRGB=null;
imageChangeRGB=null;
}
return?createImage;
}
//圖片反色處理
public?static?BufferedImage?inverse(BufferedImage?image)
{
BufferedImage?createImage=null;
if(image!=null)
{
int?width=0;
int?height=0;
width=image.getWidth();
height=image.getHeight();
int?imageRGB[]=new?int[width*height];
image.getRGB(0?0?width?height?imageRGB?0?width);
createImage=new?BufferedImage(widthheightBufferedImage.TYPE_INT_RGB);
for(int?i=0;i {
imageRGB[i]=imageRGB[i]^0xffffffff;
}
createImage.setRGB(0?0?width?height?imageRGB?0?width);
imageRGB=null;
}
return?createImage;
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????301??2011-09-14?17:30??ImageZoom\.classpath
?????文件????????385??2011-09-14?20:51??ImageZoom\.project
?????文件????????629??2011-09-14?17:30??ImageZoom\.settings\org.eclipse.jdt.core.prefs
?????文件???????2107??2011-09-15?17:32??ImageZoom\bin\ImageZoom.class
?????文件???????2285??2011-09-15?17:32??ImageZoom\bin\test.class
?????文件???????2349??2011-09-15?17:32??ImageZoom\src\ImageZoom.java
?????文件???????1315??2011-09-15?17:32??ImageZoom\src\test.java
?????目錄??????????0??2011-09-14?17:30??ImageZoom\.settings
?????目錄??????????0??2011-09-15?17:31??ImageZoom\bin
?????目錄??????????0??2011-09-15?17:31??ImageZoom\src
?????目錄??????????0??2011-09-14?17:30??ImageZoom
-----------?---------??----------?-----??----
?????????????????9371????????????????????11
評(píng)論
共有 條評(píng)論