code表现不同Android和Windows [英] Code behaves differently in Android and Windows

查看:150
本文介绍了code表现不同Android和Windows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着画上一个位图。这工作正常,在Windows,但在创建Android的分段错误(无论如何,这就是德尔福说,我只看到在Android上没有反应)。我有一个移动项目,表格只包含一个TToolbar,TSpeed​​Button,二TLabels和一个的TImage。这里有一个事件处理程序的TSpeed​​Button点击。

当我注释掉code正常工作在Android上的注释下的一切。当我尝试按照与调试器的code正常工作的过程结束。没有看到图表或segmantation故障。当我让它运行在故障发生。

我是什么做错了吗?

 程序TForm2.Button_DrawClick(发件人:TObject的);
VAR RCT:TRectF;
    H,W:的Int32;
开始
  H:= TRUNC(Image.Height);
  W:= TRUNC(Image.Width);
  Label_Height.Text:= IntToStr(H);
  LABEL_WIDTH。文:= IntToStr(瓦特);
  RCT:= TRectF.Create(20,20,瓦特 -  20中,h  -  20);
//可以在下面被注释掉//
  Image.Bitmap.Create(W,H);
  如果Image.Bitmap.Canvas.BeginScene然后
  尝试
    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);
  最后
    Image.Bitmap.Canvas.EndScene;
  结束; // try..finally
结束; // Button_DrawClick //
 

解决方案

这code是错误的所有平台。

  Image.Bitmap.Create(W,H);
 

这是运行在一个已经构建的实例构造函数。你不想这样做。你可能会摆脱它在一些平台上,但它从来没有正确的。

设置位图的尺寸是这样的:

  Image.Bitmap.SetSize(W,H);
 

您可能需要调用清除的位图了。

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). I have a mobile project, form containing only a TToolbar, TSpeedButton, two TLabels and a TImage. There's just one eventhandler for the TSpeedButton click.

When I comment out everything below the comment the code works fine in 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.

这篇关于code表现不同Android和Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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