- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个由 42 帧组成的大 spritesheet (3808x1632)。我会用这些帧呈现一个动画,我使用一个线程来加载一个包含所有帧的位图数组,并有一个等待其结束的启动画面。我没有使用 SurfaceView(和 Canvas 的绘制功能),我只是在主布局的 ImageView 中逐帧加载。我的方法类似于 Loading a large number of images from a spritesheet完成实际上需要将近 15 秒,不能接受。
我用的是这种函数:
for (int i=0; i<TotalFramesTeapotBG; i++) {
xStartTeapotBG = (i % framesInRowsTeapotBG) * frameWidthTeapotBG;
yStartTeapotBG = (i / framesInRowsTeapotBG) * frameHeightTeapotBG;
mVectorTeapotBG.add(Bitmap.createBitmap(framesBitmapTeapotBG, xStartTeapotBG, yStartTeapotBG, frameWidthTeapotBG, frameHeightTeapotBG));
}
framesBitmapTeapotBG 是一个大的 spritesheet。更深入地看,我在 logcat 中读到 createBitmap 函数需要很多时间,可能是因为 spritesheet 太大了。我在某个地方发现我可以在大 spritesheet 上创建一个窗口,使用 rect 函数和 Canvas ,创建要加载到数组中的小位图,但它不是很清楚。我说的是那个帖子:cut the portion of bitmap
我的问题是:如何加快 spritesheet 的切割速度?
编辑:我正在尝试使用这种方法,但看不到最终动画:
for (int i=0; i<TotalFramesTeapotBG; i++) {
xStartTeapotBG = (i % framesInRowsTeapotBG) * frameWidthTeapotBG;
yStartTeapotBG = (i / framesInRowsTeapotBG) * frameHeightTeapotBG;
Bitmap bmFrame = Bitmap.createBitmap(frameWidthTeapotBG, frameHeightTeapotBG, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bmFrame);
Rect src = new Rect(xStartTeapotBG, yStartTeapotBG, frameWidthTeapotBG, frameHeightTeapotBG);
Rect dst = new Rect(0, 0, frameWidthTeapotBG, frameHeightTeapotBG);
c.drawBitmap(framesBitmapTeapotBG, src, dst, null);
mVectorTeapotBG.add(bmFrame);
}
可能是 Bitmap bmFrame 管理不当。
最佳答案
简短的回答是更好的内存管理。
您正在加载的 Sprite 表很大,然后您将其复制到一堆小位图中。假设 Sprite 表不能再小了,我建议采用以下两种方法之一:
Canvas.drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
的东西直接从 sprite 表中绘制。 .这会将您的文件加载减少到一个大的分配,这可能只需要在您的 Activity 生命周期内发生一次。我认为第二个选项可能是两者中更好的一个,因为它在内存系统上更容易,并且对 GC 的工作更少。
关于android - Spritesheet 以编程方式切割 : best practices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7341017/
上下文 我有一个日间 TUMBLINGWINDOW(类似于下面所示的) SELECT DATEADD(day, -1, System.Timestamp()) AS WindowStart
因此,我正在开发一个非常小的 Web 组件,以作为更大的设计系统的一部分。 我对网络组件的使用有点陌生,但我知道这个特定的网络组件可以在一个布局中使用很多很多次。 此 Web 组件控制在传递给它的任何
我刚刚开发了一个 Android 应用程序(minSdkVersion 23/targetSdkVersion 29),可以连接到 BluetoothLE 设备以定期获取数据。 现在,在 MainAc
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
我一直在阅读有关 Airplay SDK 和 Dragonfire SDK 的内容。这些是在没有 Mac 的情况下进行 iphone 开发的合法选择吗?大家有更好的解决办法吗? 最佳答案 由于签名等原
我正在考虑使用 DTO 而不是传递我的域对象。我在这里和其他地方都读过几篇文章,我知道有几种方法可以完成这项工作。 如果我总共只有大约 10 个域类,并且考虑到我想在我的 View (WPF 前端)中
我的问题是,如果我有一个列表 list = [1,2,3,4,5,6,7] 如果我想知道这个列表中元素的数量,是len(list) 或 list.count 更好的选择?还是 .count 仅适用于来
我想知道 Django Rest Framework 的最佳实践。我一直通过每个用户使用不同的序列化程序(员工、帐户所有者、其他人)和 HTTP 方法来限制更改帐户上某些属性的访问权限,但我觉得这太不
我有数百个用于测试组件的脚本。这些脚本中的每一个都包含一组下标和单独的记录。 下标可以在多个 TC_Level 脚本中使用,甚至可以在其他下标中使用。 每个脚本都有一个唯一的名称。 例子: TC_1
我正在建立一个以两种语言提供产品信息的网站:英文和中文。 每个产品必须有英文名称,也可以有中文名称。 每次请求产品页面时,request检查对象以确定产品名称应该以英文还是中文显示。在后一种情况下,如
场景:应用程序具有可以启用某些优化的算法。默认情况下,有些是打开的,有些是关闭的。在 Java 中是否有一种方便的方法来实现某种全局属性系统? 要求: 必须很容易两次使用不同的设置运行程序的多个实例
我从事嵌入式工作,我有一些管理硬件的软件模块。这个模块有状态,状态转换很复杂:根据事件,模块可以从状态 A 到状态 B 或者可能到 C .但是,当它退出某个状态时,它应该对硬件执行一些操作,以使其也保
我有一个免费网站,可以流式传输实时股票期权数据。我想让用户制作并保存他们自己的 JavaScript 可调用工具来解释选项数据。用户可以调用这些自定义工具来帮助他们自己做出有关期权的买卖决定。 但对于
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 2 年前。 社区在 6 个
我不是 DBA,我不知道什么是最好的解决方案。我有两个表, Custumers Table CustomerId (primary key, identity) ... 和 Suppliers Tab
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 7年前关闭。 Improve t
我一直在阅读关于版本控制主题的所有问题,但我认为我没有找到一个看起来像我自己的场景。 场景是: 我们有一个中型/大型 Web 应用程序,它有(至少应该有)一个部署到所有客户端的核心。当我们向客户演示应
我希望根据继承来组织一些项目,目的是确定哪些项目是连接最密集的父项,并且还只是看到形成的连接。 通常这将通过拓扑排序来完成,但我的图有循环。是否有类似“尽力而为”拓扑排序的东西,它可以尝试根据连接数或
以下在 JQuery 中附加事件处理程序的方法有什么区别? (function () { var $body = $("body"); $('button').click(functi
我是一名优秀的程序员,十分优秀!