添加超过10帧时动态壁纸动画强行关闭?

发布于 2024-09-15 18:56:40 字数 5681 浏览 1 评论 0原文

我正在尝试用一系列启动动画 .png 制作一个简单的动态壁纸...

我正在使用

private static final int NUM_RES = 9;
        private final Bitmap[] mPics = new Bitmap[NUM_RES];
        CubeEngine() {
            Resources res = getResources();
            for (int i = 0; i< NUM_RES; i++) {
                int id = res.getIdentifier("boot_0010" + (i + 1), "drawable", "minghai.wallpaper");
                mPics[i] = BitmapFactory.decodeResource(res, id);
            }
        }

9 似乎是我能达到的最高值。如果我将 NUM_RES 设置为超过 9 的值,我会强制关闭。

我的所有文件都带有标签... boot_00101.png boot_00102.png boot_00103.png boot_00104.png boot_00105.png boot_00106.png boot_00107.png boot_00108.png boot_00109.png boot_00110.png boot_00111.png boot_00112.png boot_00113.png boot_00114.png 等等...我有大约 50 张图像正在尝试使用

有人知道我应该做什么吗?

LOGCAT:

08-21 19:18:43.108: ERROR/AndroidRuntime(6475): FATAL EXCEPTION: main
08-21 19:18:43.108: ERROR/AndroidRuntime(6475): java.lang.NullPointerException
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.graphics.Canvas.drawBitmap(Canvas.java:1115)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.drawYayoi(YayoiWallpaper.java:166)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.drawFrame(YayoiWallpaper.java:144)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.onOffsetsChanged(YayoiWallpaper.java:117)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.service.wallpaper.WallpaperService$Engine.doOffsetsChanged(WallpaperService.java:669)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:847)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.os.Looper.loop(Looper.java:123)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at java.lang.reflect.Method.invokeNative(Native Method)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at java.lang.reflect.Method.invoke(Method.java:521)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at dalvik.system.NativeStart.main(Native Method)

@Yok 非常感谢你成功了......在某种程度上,我似乎无法超过 30 我遇到了内存错误。很抱歉问,但是您是否知道一种更有效的方法来简单地获得像我想要实现的动画。

08-22 04:35:03.720: ERROR/AndroidRuntime(8783): FATAL EXCEPTION: main
08-22 04:35:03.720: ERROR/AndroidRuntime(8783): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.nativeCreate(Native Method)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.<init>(YayoiWallpaper.java:60)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at minghai.wallpaper.YayoiWallpaper.onCreateEngine(YayoiWallpaper.java:35)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:814)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.os.Looper.loop(Looper.java:123)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at java.lang.reflect.Method.invokeNative(Native Method)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at java.lang.reflect.Method.invoke(Method.java:521)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at dalvik.system.NativeStart.main(Native Method)

I'm trying to make a simple livewallpaper out of a series of boot animation .pngs...

I'm using

private static final int NUM_RES = 9;
        private final Bitmap[] mPics = new Bitmap[NUM_RES];
        CubeEngine() {
            Resources res = getResources();
            for (int i = 0; i< NUM_RES; i++) {
                int id = res.getIdentifier("boot_0010" + (i + 1), "drawable", "minghai.wallpaper");
                mPics[i] = BitmapFactory.decodeResource(res, id);
            }
        }

9 seems to be the highest I can go. If i set NUM_RES to anything over 9 i get a force close.

All my files are labeled...
boot_00101.png
boot_00102.png
boot_00103.png
boot_00104.png
boot_00105.png
boot_00106.png
boot_00107.png
boot_00108.png
boot_00109.png
boot_00110.png
boot_00111.png
boot_00112.png
boot_00113.png
boot_00114.png
and so on...I have about 50 images im trying to use

Anyone know what I should be doing?

LOGCAT:

08-21 19:18:43.108: ERROR/AndroidRuntime(6475): FATAL EXCEPTION: main
08-21 19:18:43.108: ERROR/AndroidRuntime(6475): java.lang.NullPointerException
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.graphics.Canvas.drawBitmap(Canvas.java:1115)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.drawYayoi(YayoiWallpaper.java:166)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.drawFrame(YayoiWallpaper.java:144)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.onOffsetsChanged(YayoiWallpaper.java:117)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.service.wallpaper.WallpaperService$Engine.doOffsetsChanged(WallpaperService.java:669)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:847)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.os.Looper.loop(Looper.java:123)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at java.lang.reflect.Method.invokeNative(Native Method)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at java.lang.reflect.Method.invoke(Method.java:521)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-21 19:18:43.108: ERROR/AndroidRuntime(6475):     at dalvik.system.NativeStart.main(Native Method)

@Yok
Thank you so much that did the trick....to an extent, i can't seem to go past 30 I get a memory error. Sorry to ask, but would you happen to know of a more efficient way to simply get an animation like i'm trying to achieve.

08-22 04:35:03.720: ERROR/AndroidRuntime(8783): FATAL EXCEPTION: main
08-22 04:35:03.720: ERROR/AndroidRuntime(8783): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.nativeCreate(Native Method)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:346)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:372)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at minghai.wallpaper.YayoiWallpaper$CubeEngine.<init>(YayoiWallpaper.java:60)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at minghai.wallpaper.YayoiWallpaper.onCreateEngine(YayoiWallpaper.java:35)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:814)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.os.Looper.loop(Looper.java:123)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at java.lang.reflect.Method.invokeNative(Native Method)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at java.lang.reflect.Method.invoke(Method.java:521)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-22 04:35:03.720: ERROR/AndroidRuntime(8783):     at dalvik.system.NativeStart.main(Native Method)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我太投入 2024-09-22 18:56:40

您的 for 循环更改存在问题:

"boot_0010" + (i + 1) 更改为 "boot_00" + (100+ (i + 1))

更改后的循环应该看起来像like :

       for (int i = 0; i< NUM_RES; i++) {
            int id = res.getIdentifier("boot_00" + (100 + (i + 1)), "drawable", "minghai.wallpaper");
            mPics[i] = BitmapFactory.decodeResource(res, id);
        }

您的循环的问题是,之前它用于获取第 10 个图像的 boot_001010 而不是 boot_00110 。这也是空指针异常的原因,因为 boot_001010 的图像不存在。

There is problem with your for loop change :

"boot_0010" + (i + 1) to "boot_00" + (100+ (i + 1))

Changed loop should look like :

       for (int i = 0; i< NUM_RES; i++) {
            int id = res.getIdentifier("boot_00" + (100 + (i + 1)), "drawable", "minghai.wallpaper");
            mPics[i] = BitmapFactory.decodeResource(res, id);
        }

Problem with your loop was that earlier it used to get boot_001010 instead of boot_00110 for 10th image. And same was reason for null pointer exception as image with boot_001010 is not present.

幻梦 2024-09-22 18:56:40

i为9时,表达式"boot_0010" + (i + 1)计算结果为字符串boot_001010;您可能希望它是 boot_00110

When i is 9, the expression "boot_0010" + (i + 1) evaluates to the string boot_001010; you probably wanted it to be boot_00110.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文