Problem with gif with transparent background

0 votes

I have a difficulty and error in displaying the gif with a transparent background every time I start this program. Even though my gif shows but regardless, all the images of the gif stayed on the canvas. Could anyone please help me with providing a solution?

This is the code I have used:

package zkouska3; 

import java.awt.Graphics;
import java.awt.Image; 
import java.awt.image.BufferedImage; 

import javax.swing.ImageIcon;
import javax.swing.JFrame; 

public class mainl extends JFrame{ 
        private Image TestImage; 
        private BufferedImage bf; 
        public static void main(String[] args) { new mainl(); 
} public mainl() { 
setSize(500, 500); 

    public void imageLoader() { 
    try { 
    TestImage = new         ImageIcon(this.getClass().getResource("pandulak.gif")).getImage();  
}catch(Exception e) { 
  public void paint(Graphics g){ 
  g.drawImage(TestImage, 0, 0, 300, 300, this); 
Feb 8, 2022 in Java by Soham
• 9,700 points

1 answer to this question.

0 votes

In this case, I have noticed that your gif is located in disposal = 3 which states that it requires the previous image because it renders incrementally. The error and issue I am facing is that the gif is completely black and not white.

Here are the possiblilities:


if (disposal==0) s="no animation"; 
else if (disposal==1) s="leave image as is"; 
else if (disposal==2) s="clear with background"; 
else if (disposal==3) s="restore previous image"; 
else s="reserved";

While rendering this with my decoder,  it looks like the following shown below:


Which ensures that there are two possibilities at this situation as such. One could be a transparent image with a background but still, even an average image viewer would display the same and hence, this might not be the case overall. These days, the browsers of the WEB rely on undocumented custom made extensions added to GIFs extension packets which ignores the GIF File Format for various aspects of rendering. All these use the same image LIB for decoding the GIFs with the presence of bad design/code. I presume that your GIF has an extension packet which commands the browser to use different disposal methods than the one which is present in the GIF header. This makes the GIF a buggy GIF and only a decoder of a buggy GIF can render it. The white lines have gaps between them and are not an aliasing bit. Also an incremental render will not work with a non black colour background and hence, the decoder must ignore the GIF background colour.

answered Feb 8, 2022 by Rahul
• 9,680 points

Related Questions In Java

0 votes
0 answers

Can you control GIF animation with Javascript?

Is it feasible to use Javascript to ...READ MORE

Nov 16, 2022 in Java by Nicholas
• 7,760 points
0 votes
1 answer

How can I create an executable JAR with dependencies using Maven?

<build> <plugins> <plugin> ...READ MORE

answered Apr 26, 2018 in Java by sophia
• 1,400 points
0 votes
2 answers

I'm getting following error, while i'm running code in windows xp service pack 3 with JDK 6 version.

Till you send the code, I would ...READ MORE

answered May 16, 2018 in Java by Meci Matt
• 9,460 points
0 votes
1 answer

Replacing a String with a character

Yes, you are missing out on a ...READ MORE

answered May 17, 2018 in Java by geek.erkami
• 2,680 points
0 votes
1 answer

Describe Heavy Weight Components Mean In Java Programming?

Heavy weight components like Abstract Window Toolkit ...READ MORE

answered Nov 28, 2018 in Java by Frankie
• 9,830 points
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 80,294 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
0 votes
1 answer

Failed to load resource: the server responded with a status of 404 (not found)

In order to avoid an error while ...READ MORE

answered Feb 8, 2022 in Java by Rahul
• 9,680 points
0 votes
1 answer

Angular: conditional class with *ngClass

For your information, the latest Angular version ...READ MORE

answered Feb 9, 2022 in Java by Rahul
• 9,680 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP