/**
* 水平翻转图像
* @param img
* @return
*/
public Image flipImage_H(Image img)
{
int width = img.getWidth(null);
int height = img.getHeight(null);
BufferedImage newImg = new BufferedImage(width, height, 1);
Graphics g = newImg.getGraphics();
g.drawImage(img, 0, 0, width, height, width, 0, 0, height, null);
g.dispose();
return newImg;
}
/**
* 竖直翻转图像
* @param img
* @return
*/
public Image flipImage_V(Image img)
{
int width = img.getWidth(null);
int height = img.getHeight(null);
BufferedImage newImg = new BufferedImage(width, height, 1);
Graphics g = newImg.getGraphics();
Graphics2D g2d = (Graphics2D) g;
// g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, 0.1f));
g2d.drawImage(img, 0, 0, width, height, 0, height, width, 0, null);
g2d.dispose();
return newImg;
}
/**
* 顺时针转90度
* @param img
* @return
*/
public Image getImage_rote90(Image img)
{
int width = img.getWidth(null);
int height = img.getHeight(null);
BufferedImage newImg = new BufferedImage(height, width, 1);
Graphics g = newImg.getGraphics();
Graphics2D g2d = (Graphics2D) g;
g2d.rotate(Math.toRadians(90), height, 0);
g2d.drawImage(img, height, 0, width, height, null);
g2d.dispose();
return newImg;
}
/**
* 顺时针转180
* @param img
* @return
*/
public Image getImage_rote180(Image img)
{
int width = img.getWidth(null);
int height = img.getHeight(null);
BufferedImage newImg = new BufferedImage(width, height, 1);
Graphics g = newImg.getGraphics();
g.drawImage(img, 0, 0, width, height, width, height, 0, 0, null);
g.dispose();
return newImg;
}
/**
* 顺时针转270
* @param img
* @return
*/
public Image getImage_rote270(Image img)
{
int width = img.getWidth(null);
int height = img.getHeight(null);
BufferedImage newImg = new BufferedImage(height, width, 1);
Graphics g = newImg.getGraphics();
Graphics2D g2d = (Graphics2D) g;
g2d.rotate(Math.toRadians(-90), 0, 0);
g2d.drawImage(img, -width, 0, width, height, null);
g2d.dispose();
return newImg;
}
/**
* 关于y=x翻转
* @param srcImg
* @return
*/
public Image getImage_FLIP_YISX(Image srcImg)
{
int width = srcImg.getWidth(null);
int height = srcImg.getHeight(null);
BufferedImage result = new BufferedImage(height, width, 1);
Graphics g = result.getGraphics();
Graphics2D g2d = (Graphics2D) g;
AffineTransform affineTransform = new AffineTransform(0, -1, -1, 0, height, width);
AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
affineTransformOp.filter(getClone(srcImg), result);
g2d.dispose();
return result;
}
/**
* 关于y=-x翻转
* @param srcImg
* @return
*/
public Image getImage_FLIP_YISFUX(Image srcImg)
{
int width = srcImg.getWidth(null);
int height = srcImg.getHeight(null);
BufferedImage result = new BufferedImage(height, width, 1);
Graphics g = result.getGraphics();
Graphics2D g2d = (Graphics2D) g;
AffineTransform affineTransform = new AffineTransform(0, 1, 1, 0, 0, 0);
AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
affineTransformOp.filter(getClone(srcImg), result);
g2d.dispose();
return result;
}
/**
* 得到克隆图像
* @param srcImg
* @return
*/
public BufferedImage getClone(Image srcImg)
{
int width = srcImg.getWidth(null);
int height = srcImg.getHeight(null);
BufferedImage result = new BufferedImage(width, height, 1);
Graphics g = result.getGraphics();
g.drawImage(srcImg, 0, 0, width, height, 0, 0, width, height,null);
g.dispose();
return result;
}