2011-09-22 22 views
4

我必須使用圖像作爲通知。爲此,圖像邊界應該是橢圓形狀。任何人都可以幫助我將圖像邊框更改爲圓形。 我已經提到了一個示例圖像10應該是一個圖像組件,我可以得到它的圓形狀。如何將圖像寄存器更改爲圓形

在此先感謝。 此致拉克什

enter image description here

回答

5
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; 

調整到你所需要的不同的價值觀...... enter image description here


RRUZ

+0

有沒有更簡單的方法? –

3

如果你指的是作爲一個通知彈出窗口,你可以使用windows regions。 這將允許你創建一個你想要的任何形狀的形狀窗口。

Here是一個更通用的答案,其中包括:

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

希望這是你在找什麼!

+0

更新的源謝謝Serdalis.But我的要求只有一個TImage組件。如果你知道答案,建議我。 – rakesh

+1

不要用紅色繪製所有背景圖像...您可以在圖像上定義透明顏色。用它來填充你的圖像,然後在它上面畫一個紅色的橢圓,並且你的編號在... – Whiler