How to change image frames to a circle

I need to use "Image as notification". To do this, the picture of the image must be in elliptical shape. Can someone help me change the image as a circle. I mentioned that the image of sample 10 should be a component of the image. How can I get a circle shape for him.

Thanks in advance. Your rakesh

enter image description here

+4
source share
2 answers
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 ​​you need ... enter image description here


Updated source code RRUZ

+5
source

If you refer to the popup as a notification, you can use Windows areas . This will allow you to create a form window of any desired shape.

Here is a more general 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 are looking for!

+3
source

All Articles