Car*_*sen 9 delphi firemonkey firemonkey-style
我一直在设计FireMonkey控件,但有一个问题我遇到了一些实际问题,那就是如何使用FireMonkey样式设计器(特别是Bitmap样式设计器)将位图合并到FireMonkey样式中.某些样式对象(例如,TButtonStyleObject)具有BitmapLink属性,但我无法看到它们如何在为FireMonkey控件生成的新自定义样式中工作.
让我试着让问题尽可能透明.我添加了一个样书并将其资源设置为Delphi样式目录中的MetropolisUIGreen.Style(在XE7中,它位于C:\ Users\Public\Documents\Embarcadero\Studio\16.0\Styles中).然后我打开FireMonkey样式设计器并找到按钮式样式,它由TButtonStyleObject和TButtonStyleTextObject组成,两者都是TLayout的父级.TButtonStyleObject的SourceLookup属性值为MetroGreenstyle.png,它是一个StyleName,与加载了MetropolisUIGreen.png图像的TImage相关联.
选择TButtonStyleObject(其StyleName为背景),我检查NormalLink属性,它是TBitmapLinks的集合.据我所知,我在NormalLink中定义的BitmapLink包含有关应该用于按钮的位图的信息,包括与MetroGreenstyle.png文件的矩形区域对应的坐标(SourceRect).
我的假设似乎是错误的,因为当我使用图形程序检查MetroGreenstyle.png时,这些坐标没有什么有趣的.我已经研究过的许多其他风格的BitmapLinks,有太多我发现,与sourceRect坐标似乎并不实际定义stylelookup png文件的有意义的区域.
我显然有这个错误.BitmapLink的SourceRect坐标如何定义FireMonkey在渲染控件时应使用的位图.
- 编辑我实际问了四个问题.我已将此问题更新为仅包含一个问题.我将在其他帖子中包含其他问题. -
I think there is a difference between the bitmap embedded in the .style file (embedded as a resource) and the one stored in the file (C:\Users\Public\Documents\Embarcadero\Studio\15.0\Styles\MetropolisUIGreen.png, that is 519x760).
The embedded bitmap seems to be different in size than the external file (you can check that by looking in the Style Editor, selecting the metrogreenstyle.png node, opening the property editor for MultiResBitmap and looking at the image size provided for Scale 1.00: 750x850.
This explains why coordinates seems all wrong. I don't know if it is the external file to be out of date or the opposite.
HTH!
Update: I managed to extract the bitmap stored in the .style file and I can confirm the coordinates are relative to that bitmap!
Update(2): .Style files and .fmx file are very similar so you can do:
1)用文本编辑器打开MetropolisUIGreen.Style,找到嵌入的位图(第18行),可以看到:
object TImage
StyleName = 'MetroGreenstyle.png'
MultiResBitmap = <
item
Width = 0
Height = 0
PNG = {...}
Run Code Online (Sandbox Code Playgroud)
2)新建一个FMX应用程序,在窗体上添加一个TImage并加载一个位图(任何你想要的图片)
3) 将 .Style 文件中的 PNG 值复制到 XFM 文件中。注意还要修复 Width 和 Height 属性:
MultiResBitmap = <
item
Width = 750
Height = 850
PNG = {...}
Run Code Online (Sandbox Code Playgroud)
4)你应该能够在设计时看到图片;
5) 添加一个按钮 Image1.Bitmap.SaveToFile('C:\temp\new_file.png'); 运行该程序并将文件保存到您的磁盘。:-)
| 归档时间: |
|
| 查看次数: |
1613 次 |
| 最近记录: |