欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-03-31 14:59:52
以下代码使用java将图片分割为几个部分,大家参考使用吧复制代码 代码如下:public class segmentationimage{   publ...

以下代码使用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;
}
}