【问题标题】:Using .gif file in android live wallpaper在 android 动态壁纸中使用 .gif 文件
【发布时间】:2012-03-09 05:00:11
【问题描述】:

我的问题是关于这篇文章的

Is it possible to set an animated gif file as live wallpaper in android?

这篇文章中给出的方法似乎不起作用。当我将动画 .gif 文件放入 /res/raw 文件夹时,出现一个错误,提示我的文件无法解析或不是字段。我是否应该了解原始文件夹中的资源或存在其他问题。以下是代码。

BelleEngine() 抛出 IOException {

        InputStream is = getResources().openRawResource(R.raw.ballerina);
        if (is != null) {
            try {
                mBelle = Movie.decodeStream(is);
                mBelleDuration = mBelle.duration();
            } finally {
                is.close();
            }
        } else {
            throw new IOException("Unable to open R.raw.belle");
        }

提前感谢您的帮助!

【问题讨论】:

    标签: android live-wallpaper animated-gif


    【解决方案1】:

    我已经尝试了它适用于我的示例。我也尝试过使用不同的 .gif 图像,但它们似乎没有任何问题。我的代码是 . {

     /**
         * Method to init suitable wallpaper according to time.
         */
        private void initWallpaperAccordingtoTime(InputStream inputStream) {
    
            if (inputStream != null) {
                try {
                    wallpaperGifStream = Movie.decodeStream(inputStream);
                    if (wallpaperGifStream != null) {
                        duration = wallpaperGifStream.duration();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
    
        }
    

    对该方法的调用如下。

     initWallpaperAccordingtoTime(getResources().openRawResource(
                 R.raw.android_apple));
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      相关资源
      最近更新 更多