delphi Firemonkey 图片显示拉伸不变形


本文整理自网络,侵删。

 Firemonkey 图片显示拉伸不变形
Firemonkey 实现简单的图片拉伸不变形,是利用原始图片的 "固定区" 及 "位伸区" 来达到此目的,因此必需要有此结构的图片才适合。

下面以聊天气泡为例,下图四个角为固定区,就是拉伸时,这四个区是不变的,而拉伸区,会自动依位伸的大小自动位伸:

 

//------------------------------------------------------------------------------

// Design by 龟山阿?d                                                          -

// http://www.cnblogs.com/onechen/                                             -

//------------------------------------------------------------------------------

 

unit FMX.Graphics.Helper;

 

interface

 

uses

  System.Types,

  FMX.Graphics;

 

type

 

  TCanvasHelper = class helper for TCanvas

    // 图片四角张缩

    procedure DrawBitmapCapInsets(

    const Bitmap1: TBitmap;            // 图片

    const DesRect: TRectF;             // 目的区域

    const CapInsetsRect: TRectF;       // 四角区域

    const Opacity: Single = 1.0;       // 透明度

    const HighSpeed: Boolean = False); // 高速

  end;

 

implementation

 

// 图片四角张缩

procedure TCanvasHelper.DrawBitmapCapInsets(

const Bitmap1: TBitmap;            // 图片

const DesRect: TRectF;             // 目的区域

const CapInsetsRect: TRectF;       // 四角区域

const Opacity: Single = 1.0;       // 透明度

const HighSpeed: Boolean = False); // 高速

var SrcRect: TRectF;

begin

     SrcRect := RectF(0, 0, Bitmap1.Width, Bitmap1.Height);

 

     //-------------------------------------------------------------------------

     // 最内圈 (不张缩)                                                        -

     //-------------------------------------------------------------------------

 

     // 左上

     Self.DrawBitmap(Bitmap1,

                     RectF(SrcRect.Left,

                           SrcRect.Top,

                           SrcRect.Left + CapInsetsRect.Left,

                           SrcRect.Top + CapInsetsRect.Top),

                     RectF(DesRect.Left,

                           DesRect.Top,

                           DesRect.Left + CapInsetsRect.Left,

                           DesRect.Top + CapInsetsRect.Left),

                     Opacity, HighSpeed);

 

     // 右上

     Self.DrawBitmap(Bitmap1,

                     RectF(SrcRect.Right - CapInsetsRect.Right,

                           SrcRect.Top,

                           SrcRect.Right,

                           SrcRect.Top + CapInsetsRect.Top),

                     RectF(DesRect.Right - CapInsetsRect.Right,

                           DesRect.Top,

                           DesRect.Right,

                           DesRect.Top + CapInsetsRect.Top),

                     Opacity, HighSpeed);

 

     // 左下

     Self.DrawBitmap(Bitmap1,

                     RectF(SrcRect.Left,

                           SrcRect.Bottom - CapInsetsRect.Bottom,

                           SrcRect.Left + CapInsetsRect.Left,

                           SrcRect.Bottom),

                     RectF(DesRect.Left,

                           DesRect.Bottom - CapInsetsRect.Bottom,

                           DesRect.Left + CapInsetsRect.Left,

                           DesRect.Bottom),

                     Opacity, HighSpeed);

 

     // 右下

     Self.DrawBitmap(Bitmap1,

                     RectF(SrcRect.Right - CapInsetsRect.Right,

                           SrcRect.Bottom - CapInsetsRect.Bottom,

                           SrcRect.Right,

                           SrcRect.Bottom),

                     RectF(DesRect.Right - CapInsetsRect.Right,

                           DesRect.Bottom - CapInsetsRect.Bottom,

                           DesRect.Right,

                           DesRect.Bottom),

                     Opacity, HighSpeed);

 

     // 左

     Self.DrawBitmap(Bitmap1,

                     RectF(SrcRect.Left,

                           SrcRect.Top + CapInsetsRect.Top,

                           SrcRect.Left + CapInsetsRect.Left,

                           SrcRect.Bottom - CapInsetsRect.Bottom),

                     RectF(DesRect.Left,

                           DesRect.Top + CapInsetsRect.Top,

                           DesRect.Left + CapInsetsRect.Left,

                           DesRect.Bottom - CapInsetsRect.Bottom),

                     Opacity, HighSpeed);

 

     // 上

     Self.DrawBitmap(Bitmap1,

                     RectF(SrcRect.Left + CapInsetsRect.Left,

                           SrcRect.Top,

                           SrcRect.Right - CapInsetsRect.Right,

                           SrcRect.Top + CapInsetsRect.Top),

                     RectF(DesRect.Left + CapInsetsRect.Left,

                           DesRect.Top,

                           DesRect.Right - CapInsetsRect.Right,

                           DesRect.Top + CapInsetsRect.Top),

                     Opacity, HighSpeed);

 

     // 右

     Self.DrawBitmap(Bitmap1,

                     RectF(SrcRect.Right - CapInsetsRect.Right,

                           SrcRect.Top + CapInsetsRect.Top,

                           SrcRect.Right,

                           SrcRect.Bottom - CapInsetsRect.Bottom),

                     RectF(DesRect.Right - CapInsetsRect.Right,

                           DesRect.Top + CapInsetsRect.Top,

                           DesRect.Right,

                           DesRect.Bottom - CapInsetsRect.Bottom),

                     Opacity, HighSpeed);

 

     // 下

     Self.DrawBitmap(Bitmap1,

                     RectF(SrcRect.Left + CapInsetsRect.Left,

                           SrcRect.Bottom - CapInsetsRect.Bottom,

                           SrcRect.Right - CapInsetsRect.Right,

                           SrcRect.Bottom),

                     RectF(DesRect.Left + CapInsetsRect.Left,

                           DesRect.Bottom - CapInsetsRect.Bottom,

                           DesRect.Right - CapInsetsRect.Right,

                           DesRect.Bottom),

                     Opacity, HighSpeed);

 

     // 中

     Self.DrawBitmap(Bitmap1,

                     RectF(SrcRect.Left + CapInsetsRect.Left,

                           SrcRect.Top + CapInsetsRect.Top,

                           SrcRect.Right - CapInsetsRect.Right,

                           SrcRect.Bottom - CapInsetsRect.Bottom),

                     RectF(DesRect.Left + CapInsetsRect.Left,

                           DesRect.Top + CapInsetsRect.Top,

                           DesRect.Right - CapInsetsRect.Right,

                           DesRect.Bottom - CapInsetsRect.Bottom),

                     Opacity, HighSpeed);

end;

 

end.

相关阅读 >>

Delphi 如何获取桌面图标方法

Delphi气泡提示

Delphi整理五(枚举、子界、集合)

Delphi 使用代理服务器

Delphi请求http接口中文乱码问题

Delphi 指定在ie浏览器或ie内核打开链接

Delphi 操作系统时间与web标准时间校正

Delphi 通过wmi获取u盘硬件特征码

Delphi idmessage1 idsmtp1 发送邮件支持https

Delphi 打开android应用信息

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...