1
我需要在我的一个应用程序中返回图像(作为流)。经过短暂的谷歌我找到了一个简单的解决方案,但它只适用于Opera和Chrome。 Firefox和Safari会显示一个简单的文本,其中包含响应是流的信息。返回泽西岛响应中的图像
以下是我现在就做:
@GET
@Path("/getImage")
@Produces({
"images/gif", "images/png", "images/jpg", MediaType.APPLICATION_JSON
})
public Response getImage(@QueryParam("width") Integer width, @QueryParam("height") Integer height) {
//SOME UNRELEVANT STUFF...
String mmcpath = gi.filepath;
BufferedImage image = ImageUtil.getImageFromPath(mmcpath);
if (image != null) {
// resize the image to fit the GUI's image frame
image = ImageUtil.resize(image, width, height);
InputStream is = ImageUtil.getStreamFromImage(image, FileHelper.getFileSuffix(mmcpath));
if (is != null) {
return Response.ok(is).build();
} else {
return Response.noContent().build();
}
}
return Response.noContent().build();
}
我希望有人有想法我如何改变这种方法来获得它与其他浏览器的工作压力太大。
谢谢
很好的例子!为了完整性,您还应该粘贴ImageUtil调整大小的方法。 –