简体   繁体   English

代码在Android和Windows中的行为有所不同

[英]Code behaves differently in Android and Windows

I try to draw on a bitmap. 我尝试绘制位图。 This works fine in Windows but creates a segmentation fault in Android (anyhow, that's what Delphi says, I just see no reaction on Android). 这在Windows中运行良好但在Android中创建了一个分段错误(无论如何,这就是Delphi所说的,我只是看不到Android的反应)。 I have a mobile project, form containing only a TToolbar, TSpeedButton, two TLabels and a TImage. 我有一个移动项目,表单只包含一个TToolbar,TSpeedButton,两个TLabel和一个TImage。 There's just one eventhandler for the TSpeedButton click. TSpeedButton点击只有一个事件处理程序。

When I comment out everything below the comment the code works fine in Android. 当我在评论下方注释掉所有内容时,代码在Android中运行良好。 When I try to follow with the debugger the code works fine to the end of the procedure. 当我尝试使用调试器时,代码在过程结束时工作正常。 without seeing a drawing or a segmantation fault. 没有看到绘图或分离错误。 When I let it run on the fault occurs. 当我让它运行时就发生了故障。

What am I doing wrong? 我究竟做错了什么?

procedure TForm2.Button_DrawClick (Sender: TObject);
var rct: TRectF;
    h, w: Int32;
begin
  h := Trunc (Image.Height);
  w := Trunc (Image.Width);
  Label_Height.Text := IntToStr (h);
  Label_Width .Text := IntToStr (w);
  rct := TRectF.Create(20, 20, w - 20, h - 20);
// can be commented out below //
  Image.Bitmap.Create (w, h);
  if Image.Bitmap.Canvas.BeginScene then
  try
    Image.Bitmap.Canvas.Stroke.Color := $FF0000FF;
    Image.Bitmap.Canvas.StrokeThickness := 3;
    Image.Bitmap.Canvas.DrawEllipse (rct, 20);
    Image.Bitmap.Canvas.Stroke.Color := $FF00FF00;
    Image.Bitmap.Canvas.DrawRect(rct, 0, 0, AllCorners, 40);
  finally
    Image.Bitmap.Canvas.EndScene;
  end; // try..finally
end; // Button_DrawClick //

This code is wrong on all platforms. 此代码在所有平台上都是错误的。

Image.Bitmap.Create (w, h);

That runs the constructor on an already constructed instance. 它在已构造的实例上运行构造函数。 You don't want to do that. 你不想那样做。 You might get away with it on some platforms but it's never right. 你可能会在某些平台上侥幸逃脱,但它永远不对。

Set the bitmap dimensions like this: 像这样设置位图尺寸:

Image.Bitmap.SetSize(w, h);    

You may want to call Clear on the bitmap too. 您可能也想在位图上调用Clear。

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

相关问题 代码在 Windows 和 Android 上执行不同 - Code executes differently on Windows and Android 代码在两种不同的网络类型上表现不同 - Code behaves differently on two different network type 为什么同一段(简单的)Java代码在不同的Android设备上的行为会大不相同? - Why same piece of (simple) Java code behaves very differently on different Android devices? 手动点击 Android Google Chrome 中的链接与通过代码点击链接的行为不同 - Manually clicking a link in Android Google Chrome behaves differently than clicking it through code otto eventbus for android在发布版本中表现不同 - otto eventbus for android behaves differently in release build Tensorflow训练模型在Android设备上的行为不同 - Tensorflow Retrained Model Behaves Differently on Android Device Android UI的行为与不同的显示硬件不同 - Android UI behaves differently with different display hardware Https 地址在 ios 和 android 上的行为不同 - Https address behaves differently on ios and android getRuntime()。exec(String [])函数的行为不同于getRuntime()。exec(String)(Android) - getRuntime().exec(String[]) function behaves differently to getRuntime().exec(String) (Android) android opengl应用在设备上的行为不同,z-far是否不同? - android opengl app behaves differently on device, z-far is different?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM