java - Creating 1x1 transparent gif in a Servlet -
following issue gets me lack of understanding. want create 1x1 transparent gif provided servlet:
public void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { response.setcontenttype("image/gif"); byte[] trackinggif = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x1, 0x0, 0x1, 0x0, (byte) 0x80, 0x0, 0x0, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x0, 0x0, 0x0, 0x2c, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x2, 0x2, 0x44, 0x1, 0x0, 0x3b }; bufferedimage singlepixelimage = new bufferedimage(1, 1, bufferedimage.type_4byte_abgr); color transparent = new color(0, 0, 0, 0); singlepixelimage.setrgb(0, 0, transparent.getrgb()); response.setcontenttype("image/gif"); response.getoutputstream().write(trackinggif); }
if call servlet firefox, servlet called twice , firebug tells me "the url not loaded" , shows broken image.
chrome example not call twice.
waht wrong? not valid image?
thanks in advance.
the gif data looks ok. why recreate if have data?
public void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { byte[] trackinggif = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x1, 0x0, 0x1, 0x0, (byte) 0x80, 0x0, 0x0, (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x0, 0x0, 0x0, 0x2c, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x2, 0x2, 0x44, 0x1, 0x0, 0x3b }; response.setcontenttype("image/gif"); response.setcontentlength(trackinggif.length); outputstream out = response.getoutputstream(); out.write(trackinggif); out.close(); }
the calling servlet twice believe side effect of having firefox + firebug running. bug
Comments
Post a Comment