forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   JAVA Micro Edition (http://forum.boolean.name/forumdisplay.php?f=52)
-   -   Воспроизведение gif-анимаций (http://forum.boolean.name/showthread.php?t=5181)

Sic 02.12.2007 17:54

Воспроизведение gif-анимаций
 
возможно ли воспроизвести ?

ViNT 02.12.2007 18:55

Re: Воспроизведение gif-анимаций
 
Есть один пример по этому поводу, правда сам делать не пробовал:
Код:

private String  mediaTypes[];
private final    String GIF_MIME_TYPE = "image/gif";
private boolean  gifSupported;   

// Get the media types to check for support of GIF file display
        mediaTypes = Manager.getSupportedContentTypes(null);
        int count = mediaTypes.length;

// Check list for GIF MIME type; set support flag if present
        gifSupported = false;
        for (int i = 0; i < count; i++) {
            if (mediaTypes[i] == GIF_MIME_TYPE)
                gifSupported = true;
        } // end for
Back to article


Listing Two

private static final String READ_OK = 0
String          url = "http://www.nosuchsite.net/StarTrek/enterprise.gif";

HttpConnection  hC = null;
DataInputStream dS = null;

Image          mapImage = null;


// Open the connection as an HTTPConnection; send request
    try {       
        hC = (HttpConnection) Connector.open(url);
        hC.setRequestMethod(HttpConnection.GET);
        hC.setRequestProperty("IF-Modified-Since",
                              "10 Nov 2000 17:29:12 GMT");
        hC.setRequestProperty("User-Agent","Profile/MIDP-2.0
                              Configuration/CLDC-1.1");
        hC.setRequestProperty("Content-Language", "en-CA");
    } catch (IOException e) { } // running without safety net!

// Read the data stream for the returned GIF image
    int iByteCount;
    iByteCount = (int)hC.getLength();
    dS = hC.openDataInputStream();
 
// Does J2ME implementation support native GIF format decode?
    if (gifSupported) {
        mapImage = Image.createImage(dS);  // Yes, translate data
                                            //    into an Image
    } else {
// No, do it ourselves: get instance of GIF decoder and decode stream
        GifDecoder d = new GifDecoder();
        if (d != null) {
            int err == d.read(dS);
            if (err == READ_OK) {
                mapImage = d.getImage();
            } //end if
        } end if
    } // end else

Back to article


Listing Three



// The run method for the class.
    public void run() {
    int t;
        if (gifImage != null) {
            while (action) {
                int n = d.getFrameCount();    // Get # of frames
                for (int i = 0; i < n; i++) {  // Loop through all
                    gifImage = d.getFrame(i);  // Get frame i
// Delay duration for frame i in milliseconds
                    t = d.getDelay(i);        // Get frame's delay
                    repaint();
                    serviceRepaints();
                    try {
                        Thread.sleep(t);      // Delay as directed
                    } catch (Exception ex){}
                } // end for
            } // end while
        } // end if
    } // end run


Sic 02.12.2007 19:22

Re: Воспроизведение gif-анимаций
 
Может у меня sdk старенький, но где взять gifDecoder() ????????????

ViNT 02.12.2007 20:23

Re: Воспроизведение gif-анимаций
 
Вложений: 2
Он в SDK не входит.
Это класс какого-то стороннего разработчика.


Часовой пояс GMT +4, время: 07:45.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot