17370845950

java将图片分割为几个部分示例

以下代码使用java将图片分割为几个部分,大家参考使用吧

复制代码 代码如下:
public class SegmentationImage{

   public static Icon Segmentation(String imagename,int Width,int Height,int height,int width) throws Exception{
  // 准备分割图片

     BufferedImage img1=ImageIO.read(new File(imagename));
     int half_w=img1.getWidth();
   int rgb[]=new int[half_w*img1.getHeight()];
   img1.getRGB(0, 0, half_w, img1.getHeight(), rgb, 0, half_w);
   BufferedImage img_half=new BufferedImage(half_w, img1.getHeight(), BufferedImage.TYPE_INT_ARGB);
   img_half.setRGB(Width,Height,height,img1.getHeight(), rgb,width,half_w);
   Icon returnIcon = new ImageIcon(img_half);
      return returnIcon;
}
}