使用TImage时Android下的低质量delphi用户界面设计 [英] Low quality delphi user interface design under Android when using TImage

查看:126
本文介绍了使用TImage时Android下的低质量delphi用户界面设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Android手机以多种不同的屏幕分辨率发布,并且我的用户界面使用多个TImage组件进行了蒙皮处理,因此我遇到了一个主要的开发问题,我必须相对于设备的屏幕分辨率缩放每个图像。 / p>

出于某些我无法理解的原因,在Android下,使用非常低质量的缩放器(可能是最近的缩放器)对TImage进行插值,导致图像质量非常低(即使考虑到屏幕缩放比例,并且表单的质量设置得很高,也会发生这种情况。)



由于此,这意味着我既可以预先缩放比例又可以包括同一张图片的多种不同分辨率,希望它看起来足够接近(并且会使我的应用膨胀),或者我可以使用软件算法实时缩放图片,然后缓存结果以供以后运行。 / p>

我使用软件三次缩放器选择了第二个选项,但问题是我的应用程序具有大量图像消息来源,第一次在高端移动设备上加载可能需要18秒。



我知道在硬件使用中可能需要做的事情OpenGL,但我无法找到一个清晰/干净的示例来说明如何在Android版Delphi中完成此操作。即使无需重新为OpenGL重新编码整个UI,也可以做到这一点。



我是否缺少一些明智的设计方法?
是我唯一的机会是Embarcadero的修复程序吗?

解决方案

我花了一些时间才将其锁定,但是在这里是Android本机代码,它将以比我能找到和优化的任何纯软件解决方案更快的速度高质量缩放图像:

  Androidapi.JNI.Media,Androidapi.JNI.GraphicsContentViewText,Androidapi.JNIBridge,FMX.Surfaces,FMX.Helpers.Android; 

程序AndroidResizeBitmap(srcBitmap,dstBitmap:TBitmap);
var
sJBitmap:JBitmap;
ScaledBitmap:JBitmap;
sSurface:TBitmapSurface;
开始
sSurface:= TBitmapSurface.Create;
sSurface.Assign(srcBitmap);
sJBitmap:= TJBitmap.JavaClass.createBitmap(sSurface.Width,sSurface.Height,TJBitmap_Config.JavaClass.ARGB_8888);
SurfaceToJBitmap(sSurface,sJBitmap);
ScaledBitmap:= TJBitmap.JavaClass.createScaledBitmap(sJBitmap,dstBitmap.Width,dstBitmap.Height,True);
sJBitmap:=无;
JBitmapToSurface(ScaledBitmap,sSurface);
ScaledBitmap:= nil;
dstBitmap.Assign(sSurface);
sSurface。免费;
sSurface:= nil;
结尾;


Since Android phones are released in many different screen resolutions and my user interface is "skinned" using multiple TImage components, I've hit a major development issue, I must scale each of my images relative to the device's screen resolution.

For some reason which I can not understand, under Android, TImage is interpolated using a really low quality scaler (possibly nearest-neighbor), resulting in a very low quality image display (this happens even when the screen scale is taken into consideration and the form's quality is set the high).

Due to this, it means I can either pre-scale and include multiple different resolutions of the same image, hoping that it will look 'close enough' (and bloating my app), or I can use a software algorithm to scale the images in real-time and then cache the result for later runs.

I choose the second option, using a software bicubic scaler, but the problem is that my app has so many image resources, it can take 18 seconds to load the first time on a high end mobile device.

I'm aware it may be possible to do what I need in hardware using OpenGL, but I haven't been able to find a clear/clean example of how this can be done in Delphi for Android. And even if it can be done without having to re-code the entire UI for OpenGL.

Is there something I'm missing design wise? Is a fix from Embarcadero my only chance?

解决方案

It took me a while to lock this down, but here is Android native code that will scale the image in high quality much faster than any pure software solution I could find and optimize:

uses Androidapi.JNI.Media, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNIBridge, FMX.Surfaces, FMX.Helpers.Android;

procedure AndroidResizeBitmap(srcBitmap,dstBitmap : TBitmap);
var
  sJBitmap     : JBitmap;
  ScaledBitmap : JBitmap;
  sSurface     : TBitmapSurface;
begin
  sSurface     := TBitmapSurface.Create;
  sSurface.Assign(srcBitmap);
  sJBitmap     := TJBitmap.JavaClass.createBitmap(sSurface.Width,   sSurface.Height,TJBitmap_Config.JavaClass.ARGB_8888);
  SurfaceToJBitmap(sSurface, sJBitmap);
  ScaledBitmap := TJBitmap.JavaClass.createScaledBitmap(sJBitmap,   dstBitmap.Width, dstBitmap.Height, True);
  sJBitmap     := nil;
  JBitmapToSurface(ScaledBitmap,sSurface);
  ScaledBitmap := nil;
  dstBitmap.Assign(sSurface);
  sSurface.Free;
  sSurface     := nil;
end;

这篇关于使用TImage时Android下的低质量delphi用户界面设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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