开发者

Byte Array copy in Jsp

I am trying to append 2 images (as 开发者_运维技巧byte[] ) in GoogleAppEngine Java and then ask HttpResponseServlet to display it. However, it does not seem like the second image is being appended.

Is there anything wrong with the snippet below?

...

resp.setContentType("image/jpeg");
byte[] allimages = new byte[1000000]; //1000kB in size
int destPos = 0;
for(Blob savedChart : savedCharts) {
  byte[] imageData = savedChart.getBytes(); //imageData is 150k in size
  System.arraycopy(imageData, 0, allimages, destPos, imageData.length);
  destPos += imageData.length;
}

resp.getOutputStream().write(allimages);
return;

Regards


I would expect the browser/client to issue 2 separate requests for these images, and the servlet would supply each in turn.

You can't just concatenate images together (like most other data structures). What about headers etc.? At the moment you're providing 2 jpegs butted aainst one another and a browser won't handle that at all.

If you really require 2 images together, you're going to need some image processing library to do this for you (or perhaps, as noted, AWT). Check out the ImageIO library.


Seem that you have completely wrong concept about image file format and how they works in HTML.

In short, the arrays are copied very well without problem. But it is not the way how image works.

You will need to do AWT to combine images in Java

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜