How to change image boarder to circle
Asked Answered
H

2

5

I have to use Image as Notification.For that Image boarder should be in elliptical shape.can any one help me to change my image boarder as a circle. I have mentioned an sample image 10 should be an image component.how can i get circle shape for it.

Thanks in advance. Yours Rakesh

enter image description here

Hexastich answered 22/9, 2011 at 11:48 Comment(0)
A
6
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,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, 0, Bmp.Width, 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;

Adjust the different values to what you need... enter image description here


Updated source from RRUZ

Arid answered 22/9, 2011 at 15:5 Comment(1)
Is there not an easier way?Aldana
S
3

If you are referring to a pop-up window as a Notification, you can use windows regions. This will allow you to create a shaped window of any shape you desire.

Here is a more generic answer which includes:

procedure TForm1.DrawEllipticRegion(wnd : HWND; rect : TRect);
begin
  rgn := CreateEllipticRgn(rect.left, rect.top, rect.right, rect.bottom);
  SetWindowRgn(wnd, rgn, TRUE);
end;

Hope this is what you're looking for!

Steradian answered 22/9, 2011 at 11:58 Comment(2)
Thank you Serdalis.But my requirement is only for a TImage component. suggest me if you know the answer.Hexastich
Do not draw all your background image with red... you can define a transparent color on your image. Use it to fill your image, then draw a red ellipse on it, and your number over...Arid

© 2022 - 2024 — McMap. All rights reserved.