import java.awt.*;
import java.awt.image.*;
import java.net.URL;
import javax.swing.ImageIcon;
public class ImageHandle {
//---이미지 불려오기 JAR로 압축후 내부파일에 접근할수 있도록
public static ImageIcon loadImageIcon(Object ob,String ref) // this,파일명
{
URL url=ob.getClass().getClassLoader().getResource(ref);
return new ImageIcon(url);
}
public static BufferedImage loadImage(Object ob,String ref) { // this,파일명
BufferedImage bimg = null;
try {
URL url=ob.getClass().getClassLoader().getResource(ref);
ImageIcon temp=new ImageIcon(url);
bimg=imageToBufferedImage(temp);
} catch (Exception e) {
e.printStackTrace();
}
return bimg;
}
//--- 이미지를 버퍼이미지로------------------------------------------
public static BufferedImage imageToBufferedImage(ImageIcon temp1) {
Image temp2=temp1.getImage();
BufferedImage copy = new BufferedImage(temp1.getIconWidth(),temp1.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = copy.createGraphics();
g.drawImage(temp2, 0, 0, null);
g.dispose();
return copy;
}
//---이미지 돌리기-----------------------------------------------------
public static BufferedImage rollImage(BufferedImage img[],int w,int h, int cols)
{
// 스트롤 방향은.. 아래로... 첫번째 이미지가 제일 아래로..
int time=cols%(img.length*h); //여러바퀴 돌아을때 를 생각해서
int img1=time/w; // 아래부분 이미지
int img2=img1+1; // 아래부분 이미지
if(img2==img.length)img2=0;
BufferedImage imgs = new BufferedImage(w,h, BufferedImage.TYPE_INT_ARGB); // 이미지 생성
Graphics2D g = imgs.createGraphics();
g.drawImage(img[img2],0,time%h-h,w,h,null); //윗쪽 이미지 그림
g.drawImage(img[img1],0,time%h,h,h,null); //아래쪽 이미지 그림
g.dispose();
return imgs;
}
// 이미지의 윗부분과 아래부분을 어둡게 하기 위해서...
public static BufferedImage alphaImage(BufferedImage img)
{
Graphics2D g = img.createGraphics();
int w = img.getWidth();
int h = img.getWidth();
BufferedImage img1 = new BufferedImage(w,h/5, BufferedImage.TYPE_INT_ARGB); // 윗쪽 그림자를 위해
Graphics2D g1 = img1.createGraphics();
BufferedImage img2 = new BufferedImage(w,h/5, BufferedImage.TYPE_INT_ARGB); // 아래쪽 그림자를 위해
Graphics2D g2 = img2.createGraphics();
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC);
ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f);
g1.setComposite(ac);
g1.setPaint(new GradientPaint(w/2,0, Color.black,w/2,img1.getHeight(),Color.white));
g1.fillRect(0,0,w,img1.getHeight());
g.drawImage(img1,0,0,w,img1.getHeight(),null);
g2.setComposite(ac);
g2.setPaint(new GradientPaint(w/2,0,Color.white,w/2,img2.getHeight(), Color.black));
g2.fillRect(0,0,w,img2.getHeight());
g.drawImage(img2,0,img2.getHeight()*4,w,img2.getHeight(),null);
return img;
}
// 이미지의 테두리 그리기(검정색으로)
public static BufferedImage outlineImage(BufferedImage img)
{
Graphics2D g = img.createGraphics();
int w = img.getWidth();
int h = img.getWidth();
BufferedImage imgT = new BufferedImage(w,h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g1 = imgT.createGraphics();
g1.setColor(Color.black);
g1.drawRect(0,0,w-1,h-1);
g.drawImage(imgT,0,0,null);
return img;
}
// 이미지의 테두리 그리기(검정색으로)
public static BufferedImage inlineImage(BufferedImage img,int dep)
{
Graphics2D g = img.createGraphics();
int w = img.getWidth();
int h = img.getWidth();
BufferedImage imgT = new BufferedImage(w,h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g1 = imgT.createGraphics();
for(int i=dep;i>0;i--)
{
if(i==dep)g1.setColor(new Color(100,50,50));
else g1.setColor(new Color(250,170,100));
g1.drawRect(i,i,w-i*2,h-i*2);
}
g.drawImage(imgT,0,0,null);
return img;
}
}
댓글 없음:
댓글 쓰기