【问题标题】:Why does "Bitmap.SaveToFile results black screens为什么“Bitmap.SaveToFile 结果黑屏
【发布时间】:2016-02-09 16:50:43
【问题描述】:

L.S.,

使用 Delphi (Seattle) 我已经成功地在 FireMonkey 应用程序中创建了一个绘图。我通过使用像

这样的语句来做到这一点
path.MoveTo( PointF(X1,Y1));  
path.lineto( PointF(X2,Y2));  path.AddEllipse(RectF(ILeft,ITop,IRight,Ibottom));  Image1.Bitmap.Canvas.BeginScene;  
Image1.Bitmap.Canvas.StrokeThickness := 1;  
Image1.Bitmap.Canvas.StrokeDash := TStrokeDash(0);
Image1.Bitmap.Canvas.DrawPath(path, CoI.X*2); 
Image1.Bitmap.Canvas.EndScene; 

etcetera..(lots of them)

最终的绘图在我的屏幕上看起来很完美,但是当我想保存位图并随后打开文件时,它总是显示为黑屏!为什么会这样?

我用了语句:

Image1.Bitmap.SaveToFile('AFilename.bmp');   

谁能告诉我我需要做什么才能让它正确吗? 非常感谢。

一月

【问题讨论】:

  • 我记得这样一个问题,可惜我不记得是什么解决了。
  • fmx 中不是 PNG
  • @DavidHeffernan:FMX 中的TBitmap 支持多种格式,包括 BMP、JPG 和 PNG。 Supported Image Formats
  • @JGMS:您在哪个平台上运行您的应用程序? BMP 仅在 Windows 和 OSX 上受支持。就像大卫说的那样,你可能应该改用 PNG。
  • 我在 Windows 7 和 10 上运行我的应用程序。所以 BMP 应该没问题。 JPG 也适合我。

标签: delphi canvas bitmap


【解决方案1】:

这对我有用:

procedure TForm1.Button1Click(Sender: TObject);
var
  path: TPathData;
begin
  path := TPathData.Create;
  path.MoveTo( PointF(10,10));
  path.lineto( PointF(20,20));
  path.AddEllipse(RectF(15,10,25,30));

  Image1.Bitmap := TBitmap.Create(50, 50);
  Image1.Bitmap.Canvas.BeginScene;
  Image1.Bitmap.Canvas.Clear(TAlphaColors.White);
  Image1.Bitmap.Canvas.Stroke.Color := TAlphaColors.Black;
  Image1.Bitmap.Canvas.StrokeThickness := 1;
  Image1.Bitmap.Canvas.DrawPath(path, 1);
  Image1.Bitmap.Canvas.EndScene;

  Image1.Bitmap.SaveToFile('C:\Users\me\Desktop\AFilename.png');
end;

Output AFilename.png

【讨论】:

  • 谢谢斯特凡。我在您的示例中添加了颜色定义,并使用了 png 扩展名。现在它起作用了。太好了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-31
  • 2010-10-17
  • 2011-10-10
  • 1970-01-01
  • 2016-11-16
  • 2020-03-19
  • 2016-12-06
相关资源
最近更新 更多