Willy
Willy

Reputation: 19

Android save gif from byte array

When I am using below code to save a byte array to gif, the gif file is blurred.

But if I save the byte array to a png or jpg is everything OK. Does anybody know what the problem is?

public writeToFile(byte[] array) { 
    try { 
        String path = "..."; 
        FileOutputStream stream = new FileOutputStream(path); 
        stream.write(array); 
    } catch (FileNotFoundException e) { 
        e.printStackTrace(); 
    } 
}

Upvotes: 0

Views: 1038

Answers (1)

Maveňツ
Maveňツ

Reputation: 1

GIF is limited to 256 colors and do not support real transparency.

enter image description here

You should use PNG instead of GIF because it offers better compression and features. PNG is great for small and simple images like logos, icons, etc.

JPEG has better compression with complex images like photos.

png has a wider color pallete than gif and gif is properitary while png is not. gif can do animations, what normal-png cannot. png-transparency is only supported by browser roughly more recent than IE6, but there is a Javascript fix for that problem. Both support alpha transparency. In general I would say that you should use png for most webgraphics while using jpeg for photos, screenshots, or similiar because png compression does not work too good on thoose.

Upvotes: 3

Related Questions