[Delphi (Object Pascal)] Delphi Graphic转换成Bitmap →→→→→进入此内容的聊天室

来自 , 2021-01-20, 写在 Delphi (Object Pascal), 查看 143 次.
URL http://www.code666.cn/view/99e7e6ce
  1. procedure GraphicToBitmap(const Src: Graphics.TGraphic;
  2.   const Dest: Graphics.TBitmap; const TransparentColor: Graphics.TColor);
  3. begin
  4.   // Do nothing if either source or destination are nil
  5.   if not Assigned(Src) or not Assigned(Dest) then
  6.     Exit;
  7.   // Size the bitmap
  8.   Dest.Width := Src.Width;
  9.   Dest.Height := Src.Height;
  10.   if Src.Transparent then
  11.   begin
  12.     // Source graphic is transparent, make bitmap behave transparently
  13.     Dest.Transparent := True;
  14.     if (TransparentColor <> Graphics.clNone) then
  15.     begin
  16.       // Set destination as transparent using required colour key
  17.       Dest.TransparentColor := TransparentColor;
  18.       Dest.TransparentMode := Graphics.tmFixed;
  19.       // Set background colour of bitmap to transparent colour
  20.       Dest.Canvas.Brush.Color := TransparentColor;
  21.     end
  22.     else
  23.       // No transparent colour: set transparency to automatic
  24.       Dest.TransparentMode := Graphics.tmAuto;
  25.   end;
  26.   // Clear bitmap to required background colour and draw bitmap
  27.   Dest.Canvas.FillRect(Classes.Rect(0, 0, Dest.Width, Dest.Height));
  28.   Dest.Canvas.Draw(0, 0, Src);
  29. end;
  30. //delphi/2248

回复 "Delphi Graphic转换成Bitmap"

这儿你可以回复上面这条便签

captcha