Jump to content
Sign in to follow this  
xorpas

create a round picture

Recommended Posts

how can create a round picture from bitmap  i check this code from chatgpt but not work  it save the image as it

 procedure SaveRoundedImage(SourceImage: TBitmap; SavePath: string);
var
  RoundedImage: TBitmap;
  RoundedRect: TRectF;
begin
  // Create a new bitmap for the rounded image
  RoundedImage := TBitmap.Create;
  try
    RoundedImage.SetSize(round(SourceImage.Width), round(SourceImage.Height));

    // Clear the bitmap (transparent background)
    RoundedImage.Clear(TAlphaColors.Null);

    // Create a rounded rectangle
    RoundedRect := TRectF.Create(0, 0, RoundedImage.Width, RoundedImage.Height);
    RoundedRect.Inflate(-0, -0);

    // Draw the rounded image onto the new bitmap
    RoundedImage.Canvas.BeginScene;
    try
      RoundedImage.Canvas.Fill.Color := TAlphaColors.White; // Fill with white background
      RoundedImage.Canvas.DrawRect(TRectF.Create(10, 10, 200, 270),
                                 30, 60,
                                 AllCorners, 100,
                                 TCornerType.ctRound);
      RoundedImage.Canvas.DrawBitmap(SourceImage,
        TRectF.Create(0, 0, SourceImage.Width, SourceImage.Height),
        TRectF.Create(0, 0, RoundedImage.Width, RoundedImage.Height), 1.0, True);
    finally
      RoundedImage.Canvas.EndScene;
    end;

    // Save the rounded image to a file
    RoundedImage.SaveToFile(SavePath);
  finally
    RoundedImage.Free;
  end;
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×