依赖注入
<dependency>
<groupId>gov.nist.isg</groupId>
<artifactId>pyramidio</artifactId>
<version>1.1.0</version>
</dependency>
切割图片
long startTime=System.currentTimeMillis();
File file = new File("D:\\jpg\\res");
File file1 = new File("D:\\jpg\\img\\test.png");
BufferedImage image = ImageIO.read(file1);
file.mkdirs();
ScalablePyramidBuilder spb = new ScalablePyramidBuilder();
FilesArchiver archiver = new DirectoryArchiver(file);
PartialImageReader pir = new BufferedImageReader(image);
spb.buildPyramid(pir, "test", archiver, 1);
long endTime=System.currentTimeMillis();
System.out.println("切割图片耗时:"+(endTime-startTime)/1000+"秒");
后台读取图片
@ApiOperation(value = "")
@GetMapping("/testOpenseaDragon")
public void testOpenseaDragon(HttpServletResponse response)throws Exception {
File dziFile = new File("D:\\java\\pyramidName.dzi");
DeepZoomImageReader reader = new DeepZoomImageReader(dziFile);
BufferedImage regionAtZoom0_1 = reader.getSubImage(
new Rectangle(1, 1, 200, 200), 0.1);
response.setContentType("image/gif");
OutputStream out = response.getOutputStream();
//输出流
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ImageIO.write(regionAtZoom0_1, "png", stream);
out.write(stream.toByteArray());
out.flush();
stream.flush();
stream.close();
}
查看效果,点击下面地址
github地址