Hey there,
I've recently tried adding .GIF support to client, and I've came across this thread, however, it did not support transparent gif (which I believe is what most people want, i.e to put over an interface)
Anyways I've seen one of the comments there hinting on how it should be done, and while this might not be the most efficient way of doing so (I dunno how else it could be done)
I got to fix it and decided to release it as it is really useful!
Note: I haven't changed anything, except adding the support for transparency.
Follow the guide on this thread and replace #update() with mine:
Code:
public void update() {
clearPixels();
try {
Graphics g = buffer.getGraphics();
if (g != null)
try {
if (!scaled) {
g.drawImage(image, 0, 0, component);
} else {
if (g instanceof Graphics2D) {
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_RENDERING, getScaleDetail(scaleDetail));
}
g.drawImage(image, 0, 0, width, height, component);
}
} finally {
g.dispose();
}
} catch (Exception x) {
}
overwritePixels();
}
//redraws the pixels
public void clearPixels() {
for (int i = 0; i < pixels.length; i++)
pixels[i] = 0;
}
//overwrites the pixels to the rasterizer
public void overwritePixels() {
drawOffsetX = drawOffsetY = 0;
resizeWidth = width;
resizeHeight = height;
raster = pixels;
}
Explanation:
Originally Posted by
Joshua
Each frame of the gif is being copied to the rasterizer and overwriting the current pixels at the spots it is drawing. If you want to add support for transparent gifs, you'd have to redraw the image behind your gif before each frame of the gif is drawn. Or store specific pixels in a temporary array and just copy them back to the rasterizer between passes.
I might have done it a bit different, but it seems to work with no FPS drop / any performance struggles.
(I know its flicking at one point, I'm not sure if thats the gif or because we don't till all pixels are cleared so it could process some pixels cleared and some not, not sure)
Credits;
Joshua
Killer 99
Me