Android的 - 有一个可能,使无限的印刷品吗? [英] Android - is there a possibility to make infinite canvas?

查看:82
本文介绍了Android的 - 有一个可能,使无限的印刷品吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我做的应用程序,允许用户绘制。简单的思考,只是扩展Canvas类,大部分的事情是完成的。

Currently I am doing app allowing user to draw. Simple think, just extend Canvas class and most of the thing is done.

这是我最初的想法和思路。但作为画布是相当小的,因为这只是在屏幕上什么用户看没有太多的空间可以绘制。经历文档我发现翻译()办法让我搬画布。当我移动它,有一些种类的空白,就像你将一张纸我所做的就是找​​出。我明白,这是完全正常的,正如我之前说的 - 画布上仅仅是屏幕

That was my initial thinking and idea. But as the canvas is rather small because this is only what user see on the screen there is not much possible space to draw. Going through documentation I found translate() method allowing me to move canvas. What I did find out is when I move it, there is some kind of blank space just as you would move piece of paper. I understand that this is totally normal, as I've said before - canvas is only "the screen".

我的问题是 - ?是有可能使类似无限画布这样就可以使一个巨大的画和周围的一切移动

这个问题之前,我在想两件事情是如何这样的事情可以做:

Before this question I was thinking about two things how something like this can be done:

  1. 移动画布上的所有对象的同时 - 坏主意,因为如果你有很多他们那么移动的速度是非常糟糕

  1. Move all objects on canvas simultaneously - bad idea, because if you have a lot of them then the speed of moving is very bad.

做同样的事情,因为它是在的ListView做当你与一个移动(或在屏幕上更好地看到),只在屏幕上的意见一起前一后加载到存储器,并在需要时剩下的动态载。我认为这是实现这一目标的最佳选择。

Do something similar as it is done in ListView when you move it (or better see on the screen) only views that are on the screen together with one before and one after are loaded to memory and rest is uploaded dynamically when needed. I think this is the best option to achieve this goal.

编辑:

提问/回答给我看,这是值得编辑我的问题,以澄清一些事情。

Question/answer given by Kai showed me that it is worth to edit my question to clarify some of the things.

什么都可以由用户来完成的基本假设:

Basic assumptions about what can be done by user:

  • 用户给予的机会,只绘制圆形和矩形与一些(80%左右),具有绘制(位图)他们在画布上。
  • 在我认为的在所有屏幕上将有最大的500-800矩形或圆形。
  • User is given opportunity to draw only circles and rectangles with some (around 80%) having drawable (bitmap) on them on canvas.
  • I assume that on all screens there will be maximum 500-800 rectangles or circles.

首先,考虑无穷我在想的屏幕相当大的数量 - 至少30在每边变焦1X 。我只是需要让我的用户更大的自由,他们在做什么。

First of all thinking about infinity I was thinking about quite big number of screens - at least 30 on zoom 1x in each side. I just need to give my users bigger freedom in what they are doing.

在此屏幕上都可以做到在正常 - 平局,规模( TouchListener ScaleListener DoubleTapListener )。在谈到缩放,还有一个必须关注和帆布的无限连接的另一件事。当用户被缩小然后屏幕,或在无形的邻居更precise对象应该出现适当的比例,你会缩小相机在现实生活中。

On this screen everything can be done as on normal - draw, scale (TouchListener, ScaleListener, DoubleTapListener). When talking about scaling, there is another thing that has to be concerned and connected with "infinity" of canvas. When user is zooming out then screens, or more precise objects on the invisible "neighbours" should appear with proper scaling as you would zoom out camera in real life.

这是我刚刚意识到的另一件事是在小缩放级别绘制的可能性 - 这是在两个或三个屏幕,然后放大 - 我想这应该削减,并重新计算它的一小部分。

The other thing that I've just realised is possibility of drawing at small zoom level - that is on two or three screens and then zooming in - I suppose it should cut and recalculate it as a smaller part.

我想支持的从API 10的设备,至少,而不是只有高端

关于时间的问题是最关键的。我想要的一切是尽可能顺利,所以用户不会知道新的画布被每次创建。

The question about time is the most crucial. I want everything to be as smooth as possible, so user wouldn't know that new canvas is being created each time.

推荐答案

我认为这真的取决于很多事情:

I think it really depends on a number of things:

  1. 的这种无限的画布的复杂性:如何无限就真的是有什么操作可以在其上做,等
  2. 在您需要的设备来支持
  3. 时间/资源,你想花就可以了金额

如果真的有没有那么多的对象/命​​令绘制,你不打算支持旧/低端手机,那么你就可以逃脱只画了一切。该GFX系统会做检查,只绘制但实际表明,这样你只会浪费一些时间来发送命令通过JNI边界的GFX系统以及相关的RECT检查。

If there are really not that many objects/commands to be drawn and you don't plan to support older/lower end phones, then you can get away with just draw everything. The gfx system would do the checking and only draws what would actually be shown, so you only waste some time to send commands pass JNI boundary to the gfx system and the associated rect check.

如果你决定,你需要一个更有效的方法,你可以将所有GFX对象的位置在4树形结构,所以当你搜索左上/右上/左下/右下窗口在屏幕应该显示,它会快速地发现,这个相交窗口中GFX对象,然后只画那些。

If you decided that you needs a more efficient method, you can store all the gfx objects' positions in 4 tree structures, so when you search the upper-left/upper-right/lower-left/lower-right "window" that the screen should show, it'll fast to find the gfx objects that intersects this window and then only draw those.

首先考虑无穷我想着蛮大   屏幕数 - 至少30上在各侧变焦1倍。我只需要   给我的用户更大的自由,他们在做什么。

First of all thinking about infinity I was thinking about quite big number of screens - at least 30 on zoom 1x in each side. I just need to give my users bigger freedom in what they are doing.

如果你只是故事的帆布物体的相对位置,还有你的画布的大小几乎没有限制,但可能必须提供一个按钮,使用户可以在画布上的一些问题,他们熟悉以免他们得到了自己丢失。

If you just story the relative position of canvas objects, there's practically no limit on the size of your canvas, but may have to provide a button to take users to some point on canvas that they are familiar lest they got themselves lost.

当谈到缩放,还有那已经是另外一回事   关心和帆布的无限连接。当用户   在无形的​​缩小则屏幕,以上precise对象   邻居应该出现适当的比例,你会缩小   摄像头在现实生活中。

When talking about scaling, there is another thing that has to be concerned and connected with "infinity" of canvas. When user is zooming out then screens, or more precise objects on the invisible "neighbours" should appear with proper scaling as you would zoom out camera in real life.

如果你存储在一个虚拟空间画布对象,并使用转换系数来翻译,从虚拟空间物体的屏幕空间,然后像放大/缩小将是相当琐碎,像

If you store canvas objects in a "virtual space", and using a "translation factor" to translate objects from virtual space to screen space then things like zoom-in/out would be quite trivial, something like

screenObj.left=obj.left*transFactor-offsetX;
screenObj.right=obj.right*transFactor-offsetX;
screenObj.top=obj.top*transFactor-offsetY;
screenObj.bottom=obj.bottom*transFactor-offsetY;
//draw screenObj

作为一个例子这里是我的电影,预订应用程序的截图:

As an example here's a screenshot of my movie-booking app:

在下面的窗口显示了电影院所有座位,上窗口是一个放大视图相同剧院。它们被实现为两个实例的相同的SurfaceView类,除了用户输入处理,唯一不同的是,上面的一个应用上述翻译因子

The lower window shows all the seats of a movie theater, and the upper window is a zoomed-in view of the same theater. They are implemented as two instances of the same SurfaceView class, besides user input handling, the only difference is that the upper one applies the above-mentioned "translation factor".

我认为在所有屏幕上会出现最大500-800矩形   或圆。

I assume that on all screens there will be maximum 500-800 rectangles or circles.

这其实并不是太糟糕。读你的编辑,我想,如果一个用户添加了大量的对象到画布的相同部分潜在的更大的问题是。然后,它并不重要,如果你只画那些实际显示并没有别的对象 - 你还是会得到不错的FPS,因为GPU的填充率饱和

It is actually not too bad. Reading your edit, I think a potentially bigger issue would be if an user adds a large number of objects to the same portion of your canvas. Then it wouldn't matter if you only draw the objects that are actually shown and nothing else - you'd still get bad FPS since the GPU's fill-rate is saturated.

所以,实际上有两个潜在的问题来源:

So there are actually two potential sources of issues:

  1. 有太多的平局命令(如果一切都画在画布上,而不是只绘制可见的)
  2. 在屏幕的同一部分太多的大对象(吃了GPU填充率)

这两个问题需要非常不同的策略(利用树结构:第二个使用动态生成位图缓存排序的对象,一日1次)。由于用户如何使用您的应用程序很可能比你如何设想它不同的是,我会强烈建议执行没有上述优化的功能,试图让尽可能多的人可以做检测,而进行优化,以每个瓶颈的你遇到,直到满意才能达到最佳性能。

The two issues requires very different strategy (1st one using tree structures to sort objects, 2nd one using dynamically generated Bitmap cache). Since how users use your app are likely to different than how you envisioned it to be, I would strongly recommend implementing the functions without the above optimizations, try to get as many people as possible to do testing, and then apply optimizations to each of the bottlenecks you encounter until the satisfactory performance is achieved.

其实只有500〜800的对象,你可以计算出所有物体的位置,然后检查,看看它们是否显示在屏幕上,你甚至不真正需要使用一些花哨的数据结构,就像一棵树与它自己的开销。

Actually with just 500~800 objects, you can just calculate the position of all the objects, and then check to see if they are visible on screen, you don't even really need to use some fancy data structures like a tree with its own overheads.

这篇关于Android的 - 有一个可能,使无限的印刷品吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆