Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3854514
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:38:04+00:00 2026-05-19T17:38:04+00:00

I am looking to draw an opacity ellipse in CodeGear Delphi 2010. I had

  • 0

I am looking to draw an opacity ellipse in CodeGear Delphi 2010.

I had tried to draw to an another bitmap,
I had set the bitmap transparent color(for background)
Call the ellipse method.

And in my image I draw the bitmap with opacity parameter(from overload). But it doesn’t work.

I want something like this http://www.java2s.com/Tutorial/VBImages/WPF-UseOpacityMaskAndRadialGradientBrush.PNG

Does anybody know an working method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:38:05+00:00Added an answer on May 19, 2026 at 5:38 pm

    It works for me:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      bm1, bm2: TBitmap;
    begin
      bm1 := TBitmap.Create;
      bm1.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\portrait.bmp');
    
      bm2 := TBitmap.Create;
      bm2.SetSize(bm1.Width, bm1.Height);
      bm2.Canvas.Brush.Color := clRed;
      bm2.Canvas.Pen.Style := psClear;
      bm2.Canvas.Ellipse(0, 0, bm2.Width, bm2.Height);
    
      Canvas.Draw(100, 100, bm1);
      Canvas.Draw(100, 100, bm2, 127);
    end;
    

    Sample 1

    If you want more control, you can always do the processing manually:

    procedure TForm1.Button1Click(Sender: TObject);
    type
      TRGB32Array = packed array[0..MaxInt div SizeOf(TRGBQuad)-1] of TRGBQuad;
      PRGB32Array = ^TRGB32Array;
      TScanline = TRGB32Array;
      PScanline = ^TScanline;
    var
      bm1, bm2, bm3: TBitmap;
      sc1, sc2, sc3: PScanline;
      i: Integer;
      j: Integer;
    var
      transp: real;
    const
      opacity = 0.29;
    begin
      transp := 1 - opacity;
    
      bm1 := TBitmap.Create;
      bm1.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\portrait.bmp');
    
      bm2 := TBitmap.Create;
      bm2.SetSize(bm1.Width, bm1.Height);
      bm2.Canvas.Brush.Color := clRed;
      bm2.Canvas.Pen.Style := psClear;
      bm2.Canvas.Ellipse(0, 0, bm2.Width, bm2.Height);
    
      bm3 := TBitmap.Create;
      bm3.SetSize(bm1.Width, bm1.Height);
    
      bm1.PixelFormat := pf32bit;
      bm2.PixelFormat := pf32bit;
      bm3.PixelFormat := pf32bit;
    
      for i := 0 to bm1.Height - 1 do
      begin
        sc1 := bm1.ScanLine[i];
        sc2 := bm2.ScanLine[i];
        sc3 := bm3.ScanLine[i];
        for j := 0 to bm1.Width - 1 do
          with sc3^[j] do
          begin
            rgbBlue := round(transp*sc1^[j].rgbBlue + opacity*sc2^[j].rgbBlue);
            rgbGreen := round(transp*sc1^[j].rgbGreen + opacity*sc2^[j].rgbGreen);
            rgbRed := round(transp*sc1^[j].rgbRed + opacity*sc2^[j].rgbRed);
          end;
      end;
    
      Canvas.Draw(100, 100, bm3);
    
    end;
    

    Sample 2

    You can for example let the background image be at 100 % opacity outside the ellipse:

      ...
      for i := 0 to bm1.Height - 1 do
      begin
        sc1 := bm1.ScanLine[i];
        sc2 := bm2.ScanLine[i];
        sc3 := bm3.ScanLine[i];
        for j := 0 to bm1.Width - 1 do
          if sc2^[j].rgbBlue + sc2^[j].rgbGreen + sc2^[j].rgbRed = 3*255 then
            sc3^[j] := sc1^[j]
          else
            with sc3^[j] do
            begin
              rgbBlue := round(transp*sc1^[j].rgbBlue + opacity*sc2^[j].rgbBlue);
              rgbGreen := round(transp*sc1^[j].rgbGreen + opacity*sc2^[j].rgbGreen);
              rgbRed := round(transp*sc1^[j].rgbRed + opacity*sc2^[j].rgbRed);
            end;
      end;
      ...
    

    Sample 3

    Not to mention all other cool stuff you can do with pixmap manipulation:

      ...
      for i := 0 to bm1.Height - 1 do
      begin
        sc1 := bm1.ScanLine[i];
        sc2 := bm2.ScanLine[i];
        sc3 := bm3.ScanLine[i];
        for j := 0 to bm1.Width - 1 do
          if sc2^[j].rgbBlue + sc2^[j].rgbGreen + sc2^[j].rgbRed = 3*255 then
            sc3^[j] := sc1^[j]
          else
            with sc3^[j] do
            begin
              rgbBlue := round(sin(transp*sc1^[j].rgbBlue + opacity*sc2^[j].rgbBlue));
              rgbGreen := round(transp*sc1^[j].rgbGreen + opacity*sc2^[j].rgbGreen);
              rgbRed := round(transp*sc1^[j].rgbRed + opacity*sc2^[j].rgbRed);
            end;
      end;
      ...
    

    Sample 4

    If you really don’t want to do it manually, I just figured out, you can draw the ellipse on a copy of the first bitmap, and then blend these two bitmaps:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      bm1, bm2: TBitmap;
    begin
    
      bm1 := TBitmap.Create;
      bm1.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\portrait.bmp');
    
      bm2 := TBitmap.Create;
      bm2.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\portrait.bmp');
      bm2.Canvas.Brush.Color := clRed;
      bm2.Canvas.Pen.Style := psClear;
      bm2.Canvas.Ellipse(0, 0, bm2.Width, bm2.Height);
    
      Canvas.Draw(100, 100, bm1);
      Canvas.Draw(100, 100, bm2, 127);
    end;
    

    Sample 5

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.