Java splits the image into several partial examples

  • 2020-04-01 03:15:12
  • OfStack

The following code USES Java to divide the image into several parts, we refer to use it


public class SegmentationImage{

   public static Icon Segmentation(String imagename,int Width,int Height,int height,int width) throws Exception{
  //Ready to split the picture

     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;
}
}


Related articles: