简体   繁体   English

Android,对大位图进行解码而不会降低质量/分辨率,并具有良好的用户体验

[英]Android, decoding of big bitmap without loosing quality/resolution and with good user experience

I know that it's a popular question, but I didn't find a solution for my situation and I just want to get adviсes. 我知道这是一个很普遍的问题,但是我没有找到适合自己情况的解决方案,我只是想得到建议。

I have an image, for example 4000 x 3000 px (or a bit bigger) and if I try to decode it I got OutOfMemory error. 我有一个图像,例如4000 x 3000 px(或更大),如果我尝试对其进行解码,则会收到OutOfMemory错误。 Almost all solutions I found suppose using inSampleSize option during decoding which is calculated with some special logic before. 我发现几乎所有解决方案都假定在解码期间使用inSampleSize选项,该选项是在使用某些特殊逻辑之前计算出来的。 It is described in the official android docs (Loading Large Bitmaps Efficiently). 在官方的android文档(有效加载大型位图)中对此进行了描述。

But I'm looking for the approach when I will not lose quality and resolution of image and at the same time I will give good experience for user. 但是,我正在寻找一种不会丢失图像质量和分辨率,同时又能为用户提供良好体验的方法。 So I thought about decoding of bitmap by parts, but there are a lot of discussions on the Internet which suggest that it's not possible to give user nice (smooth) experience with such approach (decoding image by part using current display bounds and scale settings would be slow). 因此,我考虑了部分解码位图的问题,但是Internet上有很多讨论表明,使用这种方法(使用当前显示范围和比例设置来部分解码图像)无法给用户带来良好的(流畅的)体验慢一点)。

I'm very interested in maximum image resolution and quality since my app is doing some measurements and it's very important to give user ability to work (scale, move, point) with the original resolution. 我对最大图像分辨率和质量非常感兴趣,因为我的应用程序正在执行一些测量,因此,使用户能够以原始分辨率工作(缩放,移动,指向)非常重要。

Could you please advise is it possible to make the second approach smooth enough to give user good experience or is there any other nice approaches for my situation? 您能否建议第二种方法是否可以足够平滑以给用户带来良好的体验,或者是否有其他适合我的方法?

If you really want to provide hight quality of image, smooth moving and etc ImageView and regular ways to do it with Android sdk will not help you. 如果您真的想提供高质量的图像,平滑移动等ImageView,而使用Android SDK的常规方法将无济于事。 I recommend you to use OpenGL for your purpose, take a look at AndEngine, it is game engine, but you can use only some of it's methods for creating one screen with your big image. 我建议您出于目的使用OpenGL,看看AndEngine,它是游戏引擎,但是您只能使用其中的一些方法来创建具有大图像的屏幕。 AndEngine is very simple to implement, just add it to your project as any other library. AndEngine的实现非常简单,只需将其与其他任何库一样添加到您的项目中即可。

Other option is to work with OpenGL without any engines with Android SDK: http://developer.android.com/guide/topics/graphics/opengl.html 另一个选择是使用OpenGL,而不使用带有Android SDK的任何引擎: http : //developer.android.com/guide/topics/graphics/opengl.html

Here is a simple algorithm of showing big texture (image) with OpenGL: 这是使用OpenGL显示大纹理(图像)的简单算法:

  1. Split your image to small images like 500x500 (if you want to support OpenGL 1, image should be power of two, like 512x512) 将图像拆分为500x500之类的小图像(如果要支持OpenGL 1,图像应为2的幂,例如512x512)
  2. Create your camera with the sizes you want (I suggest you should create it with screen sizes) 创建具有所需尺寸的相机(建议您使用屏幕尺寸创建相机)
  3. Just draw all your small pictures in render() method 只需在render()方法中绘制所有小图片
  4. For moving just move your camera. 要移动,只需移动相机即可。

PS link to AndEngine - http://www.andengine.org/ PS链接到AndEngine- http: //www.andengine.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM