本文介绍了如何在FMX.Graphics.TBitmap上绘制FMX.Surface.TBitmapSurface的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关注日期:
如何在FMX(火猴)中加载大型位图
我需要在FMX.Graphics.TBitmapTBitmapSurface上绘制内容,我在网上找到了很多答案,但是它们要么位于VLC而不是FMX,要么它们的目标是savingloading而不是在TBitmap上绘图,这就是为什么我在这里问一个新问题.
现在,这是我当前的代码,用于将图像加载到TBitmapSurface:

Follwing on:
How to load large bitmap in FMX (fire monkey)
I have come to a need to draw whats on TBitmapSurface on the FMX.Graphics.TBitmap, i have found a lot of answer regarding this on the web, but they are either in VLC instead of FMX or their goal is saving and loading instead of drawing on a TBitmap, which is why i asked a new question here.
Now here is my current code for loading my image on the TBitmapSurface :

var
  bitmapSurf: TBitmapSurface;
  path: string;
begin
  path := 'image.jpg';
  bitmapSurf := TBitmapSurface.Create;
  TBitmapCodecManager.LoadFromFile(path, bitmapSurf);
end;

现在搜索了一下之后,我发现可以在TBitmapSurface上使用Scanline了,但是我不知道如何使用它在TBitmap上绘制,在网上有人用过TBitmap.canvas.draw,但FMX!上不存在这样的东西.最后,我的目标是绘制一个很大的图像(1000 * 16000),该图像将加载到TBitmapSurface上,然后再加载到1 TBitmap 上(因为TBitmap不支持8192px,而我的身高是16000px,我需要在两个TBitmap上绘制.)
我正在使用Delphi 10.2.3.
谢谢.

Now after searching for a bit i found that i can use Scanline on the TBitmapSurface, but i didn't know how to use it to draw on the TBitmap, on the web some people had used TBitmap.canvas.draw, but such a thing doesn't exist on the FMX!.
In the end my goal is to draw a very large image (1000*16000) which is loaded in the TBitmapSurface on more then 1 TBitmap (because TBitmap doesn't support more then 8192px and my height is 16000px, i need to draw this on two TBitmap).
I am using Delphi 10.2.3.
Thanks.

推荐答案

您可以按如下所示将大图像(从文件中)拆分为两个TImage组件

You can split the large image (from a file) to two TImage components as follows

就像在代码中一样,将图像从文件加载到TBitmapSurface.

Load the image from file to a TBitmapSurface as you already do in your code.

然后创建另一个TBitmapSurface,并将其大小设置为大的一半.将大图像的前半部分复制到此表面并将其分配给Image1.Bitmap.然后将后半部分复制到此表面并将其分配给Image2.Bitmap.

Then create another TBitmapSurface and set its size to the half of the large one. Copy the first half of the large image to this surface and assign it to Image1.Bitmap. Then copy the latter half to this surface and assign that to Image2.Bitmap.

var
  srce, dest: TBitmapSurface;
  path: string;
  scan: integer;
  w, h1, h2: integer;
begin
  path := 'C:\tmp\Imgs\res.bmp';

  srce := TBitmapSurface.Create;
  try
    TBitmapCodecManager.LoadFromFile(path, srce);

    dest := TBitmapSurface.Create;
    try
      // first half
      w := srce.Width;
      h1 := srce.Height div 2;
      dest.SetSize(w, h1, TPixelFormat.RGBA);
      for scan := 0 to h1-1 do
        Move(srce.Scanline[scan]^, TBitmapSurface(dest).Scanline[scan]^, srce.Width * 4);
      Image1.Bitmap.Assign(dest);

      // second half
      h2 := srce.Height - h1;
      dest.SetSize(w, h2, TPixelFormat.RGBA);
      for scan := h1 to srce.Height-1 do
        Move(srce.Scanline[scan]^, TBitmapSurface(dest).Scanline[scan-h1]^, srce.Width * 4);
      Image2.Bitmap.Assign(dest);

    finally
      dest.Free;
    end;
  finally
    srce.Free;
  end;

这篇关于如何在FMX.Graphics.TBitmap上绘制FMX.Surface.TBitmapSurface的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 14:42