微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

delphi – 如何将图像边界更改为圆形

我必须使用 Image作为通知.对于那个图像寄宿生应该是椭圆形的形状.任何人都可以帮我改变我的图像寄宿作为一个圆圈.
 我已经提到了一个示例图像10应该是一个图像组件.我可以得到它的圆形.

提前致谢.
你的拉克什

解决方法

const
  BORDER = 3;
Var
  Bmp : TBitmap;
  w,h: Integer;
  x,y: Integer;
begin
  Bmp:=TBitmap.Create;
  try
    Bmp.PixelFormat:=pf24bit;
    Bmp.Canvas.Font.Name  :='Arial';                            // set the font to use
    Bmp.Canvas.Font.Size  :=20;                                 //set the size of the font
    Bmp.Canvas.Font.Color := clWhite;                           //set the color of the text
    w          :=Bmp.Canvas.TextWidth(IntToStr(sped1.Value));   //calculate the width of the image
    h          :=Bmp.Canvas.TextHeight(IntToStr(sped1.Value));  //calculate the height of the image
    Bmp.Width  := Max(w,h) + BORDER * 2;                       // get a square
    Bmp.Height := Max(w,h) + BORDER * 2;                       // get a square
    x          := (Bmp.Width  - w) div 2;                       // center
    y          := (Bmp.Height - h) div 2;                       // center
    Bmp.Canvas.Brush.Color := clBlue;                           //set the background
    Bmp.Canvas.FillRect(Rect(0,Bmp.Width,Bmp.Height));      //paint the background which is transparent
    Bmp.Canvas.Brush.Color := clRed;                            // circle in red
    Bmp.Canvas.Pen.Color   := clRed;                            // circle in red
    Bmp.Canvas.Ellipse(0,Bmp.Height);            // draw the circle
    Bmp.Canvas.textout(x,y,IntToStr(sped1.Value));            //draw the number
    img1.Picture.Assign(bmp);                                   // assign the bmp to the image ; image.transparent = true,.stretch = true;
  finally
    Bmp.Free;
  end;

根据您的需要调整不同的值…

RRUZ更新了源代码

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐