Delphi编写的GDI+界面类

简介:
使用Delphi2010开发的一个GDI+界面类,可以做出非常漂亮的界面。



unit  xDUISkinPanel ;
interface
uses
  Windows, Messages, SysUtils, Graphics, Classes, stdctrls, Buttons, GDIPlusUse, GdiPlus,
  GdiPlusHelpers, Controls, ExtCtrls, Math;
type
  TxDUISkinPanel = class(TGraphicControl)
  private
    FMouseOverButton: Boolean;
    FState: TButtonState;
    FOnReSize: TNotifyEvent;
    FAutoSize: Boolean;
    FParentCanvas: TCanvas;
    FSetParentCanvas: Boolean;
    FOffSetX, FOffSetY: Integer;
    FCaptionOffX: Integer;
    FCaptionOffY: Integer;
    FAlignment: TAlignment;
    FLayout: TTextLayout;
    FDrawFrame: Boolean;
    FDrawFrameColor: TColor;
    FIsCreateDisabledImg: Boolean;
    FBmp: TBitmap;
    FDivisionImg: Boolean;
    FDivisionCol: Integer;
    FDivisionRow: Integer;
    FDivisionFocused: Integer;
    FDivisionHot: Integer;
    FDivisionDown: Integer;
    FDivisionCount: Integer;
    FDivisionDisabled: Integer;
    FDivisionUp: Integer;
    FDivisionHighlight: Integer;
    FDivisionSelected: Integer;
    FImgSelectedHot: TGPBitmap;
    FCaptionShow: Boolean;
    FAlphaDrawImg: Integer;
    FData: Pointer;
    FTabStyle: Boolean;
    FIconSize: Integer;
    FReSizeLeft: Integer;
    FReSizeRight: Integer;
    FDivisionType: Integer;
    FTileRect: TRect;
    FMainImg: String;
    FBottomShading: String;
    FTopShading: String;
    FTileRectBottom: Integer;
    FTileRectTop: Integer;
    FTileRectLeft: Integer;
    FTileRectRight: Integer;
    FTopShowPic: String;
    procedure ReSizeImage(var ImgSrc: IGPBitmap);
    procedure ReSizeAllImg;
    procedure ReDraw;
    procedure ImgCopyRect(var Img: IGPBitmap; Value: Boolean);
    procedure CMEnabledChanged(var Msg: TMessage); message cm_EnabledChanged;
    procedure CMFontChanged(var Msg: TMessage); message cm_FontChanged;
    procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
    procedure SetAutoSize(const Value: Boolean);
    procedure SetAlignment(const Value: TAlignment);
    procedure SetLayout(const Value: TTextLayout);
    procedure SetDrawFrame(const Value: Boolean);
    procedure SetDrawFrameColor(const Value: TColor);
    procedure SetImgUp(const Value: IGPBitmap);
    procedure SetImgMain(const Value: IGPBitmap);
    procedure SetAlphaDrawImg(const Value: Integer);
    procedure SetTabStyle(const Value: Boolean);
    procedure SetReSizeLeft(const Value: Integer);
    procedure SetReSizeRight(const Value: Integer);
    procedure SetDivisionImg(const Value: Boolean);
    procedure SetTileRect(const Value: TRect);
    procedure SetBottomShading(const Value: String);
    procedure SetMainImg(const Value: String);
    procedure SetTopShading(const Value: String);
    procedure SetTopShowPic(const Value: String);
    { Private declarations }
  protected
    { Protected declarations }
    procedure AdjustBounds; dynamic;
    procedure Paint; override;
  public
    { Public declarations }
    ImgMain, ImgUp: IGPBitmap;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property Canvas;
    procedure Clone(Btn: TxDUISkinPanel; IsFont: Boolean = True);
    procedure CreateDisabledImg;
    property Data: Pointer read FData write FData;
  published
    { Published declarations }
    property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
    property Layout: TTextLayout read FLayout write SetLayout default tlTop;
    property AutoSize: Boolean read FAutoSize write SetAutoSize;
    property DivisionImg: Boolean read FDivisionImg write SetDivisionImg;
    property OnReSize: TNotifyEvent read FOnReSize write FOnReSize;
    property AlphaDrawImg: Integer read FAlphaDrawImg write SetAlphaDrawImg;
    property DrawFrame: Boolean read FDrawFrame write SetDrawFrame;
    property DrawFrameColor: TColor read FDrawFrameColor write SetDrawFrameColor;
    //平铺区域
    property TileRect: TRect read FTileRect write SetTileRect;
    //图片
    property MainImg: String read FMainImg write SetMainImg;
    property TopShading: String read FTopShading write SetTopShading;
    property BottomShading: String read FBottomShading write SetBottomShading;
    property TopShowPic: String read FTopShowPic write SetTopShowPic;
    property Color;
    property Enabled;
    property Visible;
    property Align;
    property Action;
    property Anchors;
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Height default 25;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property Width default 75;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
  end;
procedure GrayScale(var Image: IGPBitmap);
procedure Register;
implementation
procedure Register;
begin
  RegisterComponents('Standard', [ TxDUISkinPanel ]);
end;
procedure CloneGDIImg(var Img: IGPBitmap; Source: IGPBitmap);
var
  g: IGPGraphics;
begin
  Img := TGPBitmap.Create(Source.GetWidth, Source.GetHeight, PixelFormat32bppARGB);
  g := TGPGraphics.Create(Img);
  try
    g.DrawImage(Source, 0, 0, Source.GetWidth, Source.GetHeight);
  finally
  end;
end;
procedure GrayScale(var Image: IGPBitmap);
var
  Data: TGPBitmapData;
  W, H, y0: Integer;
  Gray, X, Y, { a, } r, g, b: Integer;
  ScanLines: array of Byte;
begin
  W := Image.GetWidth;
  H := Image.GetHeight;
  Data := Image.LockBits(MakeRect(0, 0, W, H), [ImageLockModeRead, ImageLockModeWrite],
    PixelFormat32bppARGB);
  SetLength(ScanLines, Data.Height * Data.Stride);
  Move(Data.Scan0^, ScanLines[0], Data.Height * Data.Stride);
  for Y := 0 to H - 1 do
  begin
    y0 := Y * Data.Stride;
    for X := 0 to W - 1 do
    begin
      r := ScanLines[y0 + X * 4];
      g := ScanLines[y0 + X * 4 + 1];
      b := ScanLines[y0 + X * 4 + 2];
      Gray := Round(r * 0.3 + g * 0.59 + b * 0.11);
      ScanLines[y0 + X * 4] := Gray;
      ScanLines[y0 + X * 4 + 1] := Gray;
      ScanLines[y0 + X * 4 + 2] := Gray;
    end;
  end;
  Move(ScanLines[0], Data.Scan0^, Data.Height * Data.Stride);
  SetLength(ScanLines, 0);
  Image.UnlockBits(Data);
end;
function IntToByte(i: Integer): Byte;
begin
  if i > 255 then
    Result := 255
  else if i < 0 then
    Result := 0
  else
    Result := i;
end;
procedure ChangeAlpha(var Image: IGPBitmap; alpha: Integer); // alpha=0--255
type
  PRGBAType = ^TRGBAType;
  TRGBAType = record
    Red: Byte;
    Green: Byte;
    Blue: Byte;
    alpha: Byte;
  end;
var
  Data: TGPBitmapData;
  W, H: Integer;
  X, Y, y0: Integer;
  p: PRGBAType;
begin
  W := Image.GetWidth;
  H := Image.GetHeight;
  Data := Image.LockBits(MakeRect(0, 0, W, H), [ImageLockModeRead, ImageLockModeWrite],
    PixelFormat32bppARGB);
  for Y := 0 to H - 1 do
  begin
    y0 := Y * Data.Stride;
    for X := 0 to W - 1 do
    begin
      p := PRGBAType(PChar(Data.Scan0) + y0 + X * 4);
      if p^.alpha <> 0 then
        p^.alpha := IntToByte((p^.alpha * alpha) div 255);
    end;
  end;
  Image.UnlockBits(Data);
end;
procedure DrawAlphaImage(g: IGPGraphics; Img: IGPBitmap; X, Y, alpha: Integer); overload;
var
  ImageAttributes: IGPImageAttributes;
  ColorMatrix: TGPColorMatrix;
begin
  ImageAttributes := TGPImageAttributes.Create;
  try
    { TColorMatrix 数组的 [3,3] 决定透明度 }
    ColorMatrix.M[3, 3] := alpha / 100;
    ImageAttributes.SetColorMatrix(ColorMatrix);
    g.DrawImage(Img, MakeRect(X, Y, Img.GetWidth, Img.GetHeight), 0, 0, Img.GetWidth,
      Img.GetHeight, UnitPixel, ImageAttributes);
  finally
    // ImageAttributes.Free;
  end;
end;
procedure DrawAlphaImage(g: IGPGraphics; Img: IGPBitmap; r: TRect; alpha: Integer); overload;
var
  ImageAttributes: IGPImageAttributes;
  ColorMatrix: TGPColorMatrix;
begin
  ImageAttributes := TGPImageAttributes.Create;
  try
    { TColorMatrix 数组的 [3,3] 决定透明度 }
    ColorMatrix.M[3, 3] := alpha / 100;
    ImageAttributes.SetColorMatrix(ColorMatrix);
    g.DrawImage(Img, MakeRect(r), // MakeRect(x, y, img.GetWidth, img.GetHeight),
      0, 0, Img.GetWidth, Img.GetHeight, UnitPixel, ImageAttributes);
  finally
    // ImageAttributes.Free;
  end;
end;
function ColorToGDIColor(Color: TColor; a: Byte): TGPColor;
var
  r, g, b: Byte;
begin
  r := GetRValue(Color);
  g := GetGValue(Color);
  b := GetBValue(Color);
  Result := MakeColor(a, r, g, b);
end;
function GetStretchRect(SourceWidth, SourceHeigth, StretchWidth, StretchHeigth: Integer): TRect;
var
  W, H, cw, ch: Integer;
  xyaspect: Double;
begin
  try
    W := SourceWidth;
    H := SourceHeigth;
    cw := StretchWidth;
    ch := StretchHeigth;
    begin
      xyaspect := W / H;
      if W > H then
      begin
        W := cw;
        H := Trunc(cw / xyaspect);
        if H > ch then // woops, too big
        begin
          H := ch;
          W := Trunc(ch * xyaspect);
        end;
      end
      else
      begin
        H := ch;
        W := Trunc(ch * xyaspect);
        if W > cw then // woops, too big
        begin
          W := cw;
          H := Trunc(cw / xyaspect);
        end;
      end;
    end;
    with Result do
    begin
      Left := 0;
      Top := 0;
      Right := W;
      Bottom := H;
    end;
    OffsetRect(Result, (cw - W) div 2, (ch - H) div 2);
  except
  end;
end;
constructor TxDUISkinPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle := ControlStyle - [csOpaque];
  ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents, csSetCaption, csDoubleClicks,
    csReplicatable];
  FAutoSize := True;
  FIconSize := 32;
  FCaptionShow := True;
  FCaptionOffX := 0;
  FCaptionOffY := 0;
  Width := 75;
  Height := 25;
  ImgUp := nil;
  FMouseOverButton := False;
  ImgMain := nil;
  FDivisionType:=0;
  FDivisionImg := False;
  FDivisionCount := 1;
  FDivisionUp := -1;
  FDivisionDown := -1;
  FDivisionHot := -1;
  FDivisionSelected := -1;
  FDivisionDisabled := -1;
  FDivisionFocused := -1;
  FDivisionHighlight := -1;
  FAlphaDrawImg := 100;
  FReSizeLeft := 0;
  FReSizeRight := 0;
  FTabStyle := True;
  FBmp := nil;
  if not(csDesigning in ComponentState) then
  begin
    FBmp := TBitmap.Create;
  end;
end;
destructor TxDUISkinPanel.Destroy;
begin
  inherited;
  if FBmp <> nil then
    FreeAndNil(FBmp);
end;
procedure TxDUISkinPanel. AdjustBounds ;
var
  DC: HDC;
  X: Integer;
  Rect: TRect;
  AAlignment: TAlignment;
begin
  if not(csReading in ComponentState) and FAutoSize then
  begin
    Rect := ClientRect;
    DC := GetDC(0);
    Canvas.Handle := DC;
    ReDraw;
    Canvas.Handle := 0;
    ReleaseDC(0, DC);
    X := Left;
  end;
end;

procedure TxDUISkinPanel.ReDraw;
var
  r, DestRect, ImgRect, SkinRect, SrcRect: TRect;
  g: IGPGraphics;
  Img: IGPBitmap;
  ImgBottom: Integer;
  DivisionIndex: Integer;
  DC: HDC;
  DTFormat: UINT;
  W, H: Integer;
  aCanvas: TCanvas;
  procedure DrawImg(ImgRect, DestRect: TRect);
  var
    ImgDes: IGPBitmap;
  begin
    g := TGPGraphics.Create(FBmp.Canvas.Handle);
    try
      ReSizeImg(ImgDes, Img, DestRect, 0, 0, Point(0, Img.Width - 0));
      g.DrawImage(ImgDes,
                  MakeRect(DestRect.Left, DestRect.Top, DestRect.Right - DestRect.Left, DestRect.Bottom - DestRect.Top),
                  ImgRect.Left,
                  ImgRect.Top,
                  ImgRect.Right - ImgRect.Left,
                  ImgRect.Bottom - ImgRect.Top,
                  UnitPixel);
    finally
    end;
  end;
  //平铺绘制
  procedure TileDrawImg(ImgRect, DestRect: TRect);
  var
    ImgDes: IGPBitmap;
    cx, cy, x, y, i, j: Integer;
    DestWidth, DestHeight: Integer;
    cRect: TRect;
  begin
    g := TGPGraphics.Create(FBmp.Canvas.Handle);
    try
      DestWidth:=DestRect.Right - DestRect.Left;
      DestHeight:=DestRect.Bottom - DestRect.Top;
      cx:=(DestWidth + (Img.Width - 1))  div Img.Width;
      cy:=(DestHeight + (Img.Height - 1)) div Img.Height;
      for I := 0 to cx - 1 do
      begin
        for j := 0 to cy - 1 do
        begin
          x:=i * Img.Width;
          y:=j * Img.Height;
          g.DrawImage(img, x, y, Img.width, Img.height);
        end;
      end;
    finally
    end;
  end;
begin
  try
    if csDesigning in ComponentState then
      with Canvas do
      begin
        Brush.Color := Color;
        Pen.Style := psDash;
        Brush.Style := bsClear;
        Rectangle(0, 0, Width, Height);
        r := ClientRect;
        OffsetRect(r, FCaptionOffX, FCaptionOffY);
        Exit;
      end;
    with FBmp do
    begin
      Width := Self.Width;
      Height := Self.Height;
      Canvas.CopyRect(ClientRect, Self.Canvas, ClientRect);
      Img:=ImgUp;
      ImgBottom := r.Top;
      if Img = nil then
        Img := ImgUp;
      if Img <> nil then
      begin
        ImgRect:=Rect(0, 0, ImgUp.Width, ImgUp.Height);
        SkinRect:=ClientRect;
        {绘制顶部}
        //加载左上图像并绘制
        DestRect:=Rect(0, 0, FTileRect.Left, FTileRect.Top);
        SrcRect:=Rect(0, 0, FTileRect.Left, FTileRect.Top);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        //加载右上图像并绘制
        DestRect:=Rect(SkinRect.Right - (ImgRect.Right - FTileRect.Right), 0, SkinRect.Right, FTileRect.Top);
        SrcRect:=Rect(FTileRect.Right, 0, ImgRect.Right, FTileRect.Top);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        //拉伸上边的图像
        DestRect:=Rect(FTileRect.Left, 0, SkinRect.Right - (ImgRect.Right - FTileRect.Right), FTileRect.Top);
        SrcRect:=Rect(FTileRect.Left, 0, FTileRect.Right, FTileRect.Top);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制底部}
        //加载下上图像并绘制
        DestRect:=Rect(0, SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom), FTileRect.Left, SkinRect.Bottom);
        SrcRect:=Rect(0, FTileRect.Bottom, FTileRect.Left, ImgRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        //加载右下图像并绘制
        DestRect:=Rect(SkinRect.Right - (ImgRect.Right - FTileRect.Right), SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom), SkinRect.Right, SkinRect.Bottom);
        SrcRect:=Rect(FTileRect.Right, FTileRect.Bottom, ImgRect.Right, ImgRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        //拉伸下边的图像
        DestRect:=Rect(FTileRect.Left, SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom), SkinRect.Right - (ImgRect.Right - FTileRect.Right), SkinRect.Bottom);
        SrcRect:=Rect(FTileRect.Left, FTileRect.Bottom, FTileRect.Right, ImgRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制左边}
        DestRect:=Rect(0, FTileRect.Top, FTileRect.Left, SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom));
        SrcRect:=Rect(0, FTileRect.Top, FTileRect.Left, FTileRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制右边}
        DestRect:=Rect(SkinRect.Right - (ImgRect.Right - FTileRect.Right), FTileRect.Top, SkinRect.Right, SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom));
        SrcRect:=Rect(FTileRect.Right, FTileRect.Top, ImgRect.Right, FTileRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制中间}
        DestRect.Left:=FTileRect.Left;
        DestRect.Top:=FTileRect.Top;
        DestRect.Right:=SkinRect.Right - (ImgRect.Right - FTileRect.Right);
        DestRect.Bottom:=SkinRect.Bottom - (ImgRect.Bottom - FTileRect.Bottom);
        SrcRect:=Rect(FTileRect.Left, FTileRect.Top, FTileRect.Right, FTileRect.Bottom);
        if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
        begin
          Exit;
        end;
        DrawImg(SrcRect, DestRect);
        {绘制上底纹}
        if FileExists(FTopShading) then
        begin
          SkinRect:=ClientRect;
          Img:=TGPBitmap.Create(FTopShading);
          SkinRect.Bottom:=Img.Height;
          SkinRect.Right:=Img.Width;
          DestRect:=SkinRect;
          SrcRect:=Rect(0, 0, Img.Width, Img.Height);
          if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
          begin
            Exit;
          end;
          DrawImg(SrcRect, DestRect);
        end;
        {绘制下底纹}
        if FileExists(FBottomShading) then
        begin
          SkinRect:=ClientRect;
          Img:=TGPBitmap.Create(FBottomShading);
          SkinRect.Left:=SkinRect.Right - Img.Width;
          SkinRect.Top:=SkinRect.Bottom - Img.Height;
          DestRect:=SkinRect;
          SrcRect:=Rect(0, 0, Img.Width, Img.Height);
          if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
          begin
            Exit;
          end;
          DrawImg(SrcRect, DestRect);
        end;
        {绘制顶部显示图片(游戏名称)}
        if FileExists(FTopShowPic) then
        begin
          SkinRect:=ClientRect;
          Img:=TGPBitmap.Create(FTopShowPic);
          SkinRect.Bottom:=Img.Height;
          SkinRect.Right:=Img.Width;
          DestRect:=Rect(60, 15, Img.Width + 60, Img.Height + 15);
          SrcRect:=Rect(0, 0, Img.Width, Img.Height);
          if (DestRect.Bottom = 0) or (DestRect.Top < 0) then
          begin
            Exit;
          end;
          DrawImg(SrcRect, DestRect);
        end;
      end;
    end;
    Canvas.Draw(0, 0, FBmp);
  finally
  end;
end;
procedure TxDUISkinPanel.ReSizeAllImg;
begin
  if (FReSizeLeft = 0) or (FReSizeRight = 0) then
    Exit;
  ReSizeImage(ImgUp);
end;
procedure TxDUISkinPanel.ReSizeImage(var ImgSrc: IGPBitmap);
var
  Img: IGPBitmap;
  r: TRect;
begin
  if (ImgSrc <> nil) and (FReSizeLeft <> 0) and (FReSizeRight <> 0) then
  begin
    r := ClientRect;
    ReSizeImg(Img, ImgSrc, r, FReSizeLeft, FReSizeRight,
      Point(FReSizeLeft, ImgSrc.Width - FReSizeLeft - FReSizeRight));
    ImgSrc := Img;
  end;
end;
procedure TxDUISkinPanel.Paint;
begin
  ReDraw;
end;
procedure TxDUISkinPanel.SetAutoSize(const Value: Boolean);
begin
  FAutoSize := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetBottomShading(const Value: String);
begin
  FBottomShading := Value;
end;
procedure TxDUISkinPanel.SetAlignment(const Value: TAlignment);
begin
  FAlignment := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetLayout(const Value: TTextLayout);
begin
  FLayout := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetMainImg(const Value: String);
begin
  FMainImg := Value;
end;
procedure TxDUISkinPanel.SetReSizeLeft(const Value: Integer);
begin
  FReSizeLeft := Value;
  ReSizeAllImg;
  Invalidate;
end;
procedure TxDUISkinPanel.SetReSizeRight(const Value: Integer);
begin
  FReSizeRight := Value;
  ReSizeAllImg;
  Invalidate;
end;
procedure TxDUISkinPanel.CMEnabledChanged(var Msg: TMessage);
begin
  inherited;
  Invalidate;
end;
procedure TxDUISkinPanel.CMFontChanged(var Msg: TMessage);
begin
  Invalidate;
end;
procedure TxDUISkinPanel.Clone(Btn: TxDUISkinPanel; IsFont: Boolean = True);
begin
  ImgUp := Btn.ImgUp;
  if IsFont then
    Font := Btn.Font;
  Alignment := Btn.Alignment;
  Layout := Btn.Layout;
end;
procedure TxDUISkinPanel.CMColorChanged(var Message: TMessage);
begin
end;
procedure TxDUISkinPanel.SetDrawFrame(const Value: Boolean);
begin
  FDrawFrame := Value;
end;
procedure TxDUISkinPanel.SetDrawFrameColor(const Value: TColor);
begin
  FDrawFrameColor := Value;
end;
procedure TxDUISkinPanel.CreateDisabledImg;
var
  Img: IGPBitmap;
begin
  if ImgUp <> nil then
  begin
    FIsCreateDisabledImg := True;
    CloneGDIImg(Img, ImgUp);
    GrayScale(Img);
  end;
end;
procedure TxDUISkinPanel.SetImgUp(const Value: IGPBitmap);
begin
  if ImgUp <> Value then
  begin
    ImgUp := Value;
  end;
end;
procedure TxDUISkinPanel.SetImgMain(const Value: IGPBitmap);
begin
  ImgMain := Value;
end;
procedure TxDUISkinPanel.ImgCopyRect(var Img: IGPBitmap; Value: Boolean);
var
  W, H, X, Y: Integer;
  r: TRect;
  g: IGPGraphics;
begin
  if Value and (ImgMain <> nil) then
  begin
    W := ImgMain.GetWidth;
    H := ImgMain.GetHeight;
    Y := H;
    r := Rect(0, 0, W, Y);
    OffsetRect(r, 0, 0);
    Img := TGPBitmap.Create(W, Y, PixelFormat32bppARGB);
    g := TGPGraphics.Create(Img);
    try
      g.DrawImage(ImgMain, MakeRect(0, 0, Img.GetWidth, Img.GetHeight), r.Left, r.Top, Img.GetWidth, Img.GetHeight, UnitPixel);
    finally
    end;
  end;
end;
procedure  TxDUISkinPanel .SetAlphaDrawImg(const Value: Integer);
begin
  FAlphaDrawImg := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetTabStyle(const Value: Boolean);
begin
  FTabStyle := Value;
  Invalidate;
end;
procedure TxDUISkinPanel.SetTileRect(const Value: TRect);
begin
  FTileRect := Value;
end;
procedure TxDUISkinPanel.SetTopShading(const Value: String);
begin
  FTopShading := Value;
end;
procedure TxDUISkinPanel.SetTopShowPic(const Value: String);
begin
  FTopShowPic := Value;
end;
procedure TxDUISkinPanel.SetDivisionImg(const Value: Boolean);
begin
  //开始绘制Skin
  FDivisionImg:=Value;
  if not FileExists(FMainImg) then
  begin
    Exit;
  end;
  ImgMain:=TGPBitmap.Create(FMainImg);
  ImgCopyRect(ImgUp, Value);
  Invalidate;
end;

end.

本文转自狗窝博客51CTO博客,原文链接http://blog.51cto.com/fxh7622/701028如需转载请自行联系原作者


fxh7622

相关文章
|
API 开发者
接口开放平台的产品设计脑图及解决方案
接口开放平台的产品设计脑图及解决方案
|
机器学习/深度学习 算法 计算机视觉
深度学习目标检测系列:一文弄懂YOLO算法|附Python源码
本文是目标检测系列文章——YOLO算法,介绍其基本原理及实现细节,并用python实现,方便读者上手体验目标检测的乐趣。
55826 0
|
7月前
|
人工智能 自然语言处理 Java
Spring AI Alibaba实战:从0到1构建企业级智能应用
本文介绍了基于SpringAI Alibaba框架开发AI原生应用的实战指南。文章首先分析了SpringAI Alibaba作为SpringAI本土化版本的核心优势,包括深度适配阿里云生态、中文语境优化等特性。随后详细讲解了开发环境的搭建过程,包括JDK17、SpringBoot3.2.2等技术栈的配置。通过三个实战案例展示了核心功能实现:基础文本生成、结合MyBatisPlus的智能问答系统、以及流式响应和函数调用等高级特性。
5839 6
|
10月前
|
机器学习/深度学习 传感器 算法
基于yolo8的深度学习室内火灾监测识别系统
本研究基于YOLO8算法构建室内火灾监测系统,利用计算机视觉技术实现火焰与烟雾的实时识别。相比传统传感器,该系统响应更快、精度更高,可有效提升火灾初期预警能力,保障生命财产安全,具有重要的应用价值与推广前景。
|
Go
链接服务器 "(null)" 的 OLE DB 访问接口 "SQLNCLI11" 指示该对象没有列,或当前用户没有访问该对象的权限。
原文:链接服务器 "(null)" 的 OLE DB 访问接口 "SQLNCLI11" 指示该对象没有列,或当前用户没有访问该对象的权限。   SELECT * FROM OPENROWSET('SQLOLEDB', 'server=.
6674 0
|
Java 数据安全/隐私保护 Python
业务对象
确定业务对象 首先需要确定应用程序的业务对象,例如用户、订单、商品等。一般情况下,业务对象应该与业务域相对应,并符合业务场景的特点。 定义业务对象属性 在确定业务对象之后,可以定义其属性,如用户包含用户名、密码、邮箱等属性。属性应该满足业务需求,并且尽可能地避免冗余和不必要的信息。 设计业务对象方法 业务对象还应该定义一些方法,例如在用户对象中,可以定义登录、注册、修改密码等方法。方法应该满足业务需求,具有一定的复用性和可扩展性。 考虑业务对象关系 在设计业务对象时,还需要考虑业务对象之间的关系,例如一个订单对象可能包含多个商品对象。可以使用关联属性、外键等方式来实现业务对象之间的关系。
|
安全 Windows
“由于启动计算机时出现了页面文件配置问题,Windows在你的计算机上创建了一个临时页面文件。。。”的问题解决
本文主要介绍了因清理电脑垃圾文件时误删虚拟内存导致的Windows页面文件配置问题,并提供了详细的解决步骤。问题表现为开机后出现临时页面文件创建的提示弹窗。解决方法包括通过控制面板或快捷键进入高级系统设置,进而调整虚拟内存设置:进入性能选项中的虚拟内存栏,选择自动管理所有驱动器的分页文件大小,最后确认并重启计算机以恢复正常运行。
10169 5
“由于启动计算机时出现了页面文件配置问题,Windows在你的计算机上创建了一个临时页面文件。。。”的问题解决
|
前端开发 JavaScript API
如何快速学习React?
如何快速学习React?
465 1
|
机器学习/深度学习 监控 安全
火焰检测识别
火焰识别技术利用深度学习算法,实现在火灾监测、工业安全、智能家居等领域的自动化检测。通过卷积神经网络(CNN)等模型,该技术能有效识别火焰,提高响应速度和安全性。文章介绍了火焰识别的应用场景、技术挑战、实现框架及代码示例,帮助读者深入了解这一技术。
|
JavaScript vr&ar 数据库
技术笔记:Js获取当前日期时间及其它操作
技术笔记:Js获取当前日期时间及其它操作
928 1