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

  • SEARCH
  • Home
  • 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 8070535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:25:11+00:00 2026-06-05T13:25:11+00:00

My task is: Create a TBitmap object. Fill it with transparent color (alpha =

  • 0

My task is:

  1. Create a TBitmap object.
  2. Fill it with transparent color (alpha = 0).
  3. Assign this bitmap to TPngImage.
  4. Save PNG file with alpha transparency.

How can I do it in Delphi XE?

var
  Png: TPngImage;
  X, Y: Integer;
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create();
  Bitmap.PixelFormat := pf32bit;
  Png := TPngImage.Create();
  try
    Bitmap.SetSize(100, 100);

    // How to clear background in transparent color correctly?
    // I tried to use this, but the image in PNG file has solid white background:
    for Y := 0 to Bitmap.Height - 1 do
      for X := 0 to Bitmap.Width - 1 do
        Bitmap.Canvas.Pixels[X, Y]:= $00FFFFFF;

    // Now drawing something on a Bitmap.Canvas...
    Bitmap.Canvas.Pen.Color := clRed;
    Bitmap.Canvas.Rectangle(20, 20, 60, 60);

    // Is this correct?
    Png.Assign(Bitmap);
    Png.SaveToFile('image.png');
  finally
    Png.Free();
    Bitmap.Free();
  end;
end;
  • 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-06-05T13:25:12+00:00Added an answer on June 5, 2026 at 1:25 pm

    More or less a copy of Dorin’s answer.
    It shows how to make a transparent png image and how to clear the background.

    uses
      PngImage;
    ...
    
    var
      bmp: TBitmap;
      png: TPngImage;
    begin
      bmp := TBitmap.Create;
      bmp.SetSize(200,200);
    
      bmp.Canvas.Brush.Color := clBlack;
      bmp.Canvas.Rectangle( 20, 20, 160, 160 );
    
      bmp.Canvas.Brush.Style := bsClear;
      bmp.Canvas.Rectangle(1, 1, 199, 199);
    
      bmp.Canvas.Brush.Color := clWhite;
      bmp.Canvas.Pen.Color := clRed;
      bmp.Canvas.TextOut( 35, 20, 'Hello transparent world');
    
      bmp.TransparentColor := clWhite;
      bmp.Transparent := True;
    
      png := TPngImage.Create;
      png.Assign( bmp );
      png.SaveToFile( 'C:\test.png' );
    
      bmp.Free;
      png.Free;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If the task is to create a csv file out of some data where
I have been given a task to create a Python file that will take
Using below code, I am getting this error: NSTask: Task create for path '/Users/media/Library/Developer/Xcode/DerivedData/Manager-gnixeptcszdoubbnfcncumzypwge/Build/Products/Debug/lib'
Working on a homework assignment and am stuck with this task: Create a loop
So I have this task to create a horizontal scrolling array of image buttons
I am trying to figure out how to accomplish the following task: Create a
I want to create Task in Google Calendar using Google Calendar API.Using C#. Looking
I got handed the task to create a Windows Phone app and i am
I've been given the task to create a simple Silverlight chat box for two
I was recently given a task to create a blog using Ruby on Rails.

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.