在delphi / android上如何在画布上画一个TbitmapSurface? [英] on delphi/android how to draw a TbitmapSurface on a Canvas?

查看:907
本文介绍了在delphi / android上如何在画布上画一个TbitmapSurface?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在delphi下(和firemonkey / android下),在Tcanvas上绘制TbitmapSurface最快的方法是什么?



我尝试使用TTexture像MyTexture.Assign(aBitmapSurface),后来做TCustomCanvasGpu(Canvas).DrawTexture,但MyTexture.Assign(aBitmapSurface)有两个主要的缺点: p>


  1. 必须在主线程内完成(我不知道为什么还有黑屏)

  2. 这是相对较慢的操作


解决方案

我不使用/极端的偏见。因为 Delphi 使用 VCL ,所以我坚持下去。如果 Android 下的 Delphi 则不会忽略此答案。



看起来这是类似的问题当访问任何操作系统视觉内容(无论是否通过 GDI WinAPI )从外部主线程访问 Windows 使操作系统API 无效,使奇怪的事情就像随机崩溃,错误渲染等。另一个原因可能是使用通常绑定到进程/线程的 GPU 相关调用,设备上下文所以为了使线程安全,你可能必须创建共享的上下文,如果不需要坚持主线程。



分配您正在创建新的图像并复制旧的,需要时间相当于绘制本身,而不是提到具有缓慢记忆的设备,它可以真的减缓整个事情相当多。



如果您正在处理 VCL 图形组件,请直接尝试使用 Draw




  • blablabla-> Canvas-> Draw(x,y,aBitmapSurface);



如果 blablabla aBitmapSurface 有效的gfx组件然后它应该工作。正如我提到不知道这是否也在Android中。 x,y 是您要绘制 aBitmapSurface 的位置。还有 StretchDraw ,如果您需要重新缩放,但有点慢。



请参阅在C 部分 GDI GDI位图中显示一系列颜色,了解 VCL


Under delphi (and under firemonkey/android), What is the most fastest way to draw on a Tcanvas a TbitmapSurface ?

I try to use TTexture like MyTexture.Assign(aBitmapSurface) and later do TCustomCanvasGpu(Canvas).DrawTexture but MyTexture.Assign(aBitmapSurface) have 2 main drawbacks :

  1. it's must be done inside the main thread (i don't know why else we have black screen)
  2. it's relatively slow operation

解决方案

I do not use/code for Android so read with extreme prejudice. As Delphi uses VCL so I stick to it. If Delphi under Android does not then you can ignore this answer.

It looks like it is similar problem to Windows when accessing any OS visual stuff (does not matter if by GDI or WinAPI) from outside main thread will invalidate the OS API making weird things latter like random crashes, wrong rendering, etc. Another reason can be the use of GPU related calls which are usually bound to process/thread and device context. So to make it thread safe you could have to create shared context if possible if not you need to stick to main thread.

By Assign you are creating new image and copy the old to it that takes time comparable to drawing itself not to mention on devices with slow memory it can really slow down the whole thing considerably a lot more.

If you are dealing with VCL graphic components then try to use Draw directly:

  • blablabla->Canvas->Draw(x,y,aBitmapSurface);

if blablabla and aBitmapSurface are valid gfx components then it should work. As I mentioned not sure if this is present also in Android. The x,y is the position where you want to draw the aBitmapSurface. There is also StretchDraw if you need to rescale but that is a bit slower.

See Display an array of color in C sections GDI and GDI Bitmap for some ideas under VCL

这篇关于在delphi / android上如何在画布上画一个TbitmapSurface?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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