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 3321116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:01:27+00:00 2026-05-17T23:01:27+00:00

hi there here it is my code: procedure TForm4.Button1Click(Sender: TObject); var png: TPNGImage; data:

  • 0

hi there
here it is my code:

procedure TForm4.Button1Click(Sender: TObject);
var
  png: TPNGImage;
  data: PRGBQarray;
  p: ^tagRGBQuad;
  i, o: integer;
begin
  png := TPNGImage.Create;
  try
    png.LoadFromFile('C:\Untitled.png');
    for o := 1 to 100 do
    begin
      data:=png.Scanline[o];
      for I := 1 to 400 do
      begin
        p := @data^[i];
        p.rgbGreen := p.rgbBlue;
        p.rgbRed := p.rgbGreen;
      end;
    end;
    img.picture.Assign(png);
  finally
    png.Free;
  end;
end;

it doesn’t work and it makes the pic messy, I’m sure it’s because of the rgbReserved.
what should i do?

  • 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-17T23:01:27+00:00Added an answer on May 17, 2026 at 11:01 pm

    This is how to greyify a bitmap. (And, yes, if you want to greyify a PNG, you first need to get the bitmap data out of it. I think the VCL will do this for you.)

    type
      PRGB32Array = ^TRGB32Array;
      TRGB32Array = packed array[0..MaxInt div SizeOf(TRGBQuad)-1] of TRGBQuad;
    
    procedure MakeGrey(Bitmap: TBitmap);
    var
      w, h: integer;
      y: Integer;
      sl: PRGB32Array;
      x: Integer;
      grey: byte;
    begin
      Bitmap.PixelFormat := pf32bit;
      w := Bitmap.Width;
      h := Bitmap.Height;
      for y := 0 to h - 1 do
      begin
        sl := Bitmap.ScanLine[y];
        for x := 0 to w - 1 do
          with sl[x] do
          begin
            grey := (rgbBlue + rgbGreen + rgbRed) div 3;
            rgbBlue := grey;
            rgbGreen := grey;
            rgbRed := grey;
          end;
      end;
    end;
    

    Sample usage:

    procedure TForm4.Button1Click(Sender: TObject);
    var
      bm: TBitmap;
    begin
      bm := TBitmap.Create;
      try
        bm.LoadFromFile('C:\Users\Andreas Rejbrand\Pictures\Porträtt, litet, kvadratiskt.bmp');
        MakeGrey(bm);
        Canvas.Draw(0, 0, bm);
      finally
        bm.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here I provide simple piece of code. function GetStringList:TStringList; var i:integer; begin Result:=TStringList.Create; Result.Add('Adam');
I am compiling a legacy C code here and there is a lot of
We have some old C code here that's built with nmake. Is there an
Here is my code example: type TMyBaseClass = class public procedure SomeProc; virtual; end;
I had a similar question answered Here There is a slight twist to the
I've been reading things here and there for a while now about using an
I've heard bits and pieces here and there, but I have yet find a
I've heard people talking about base 64 encoding here and there. What is it
There is a similar question here but it only covers some of the issues
There is an interesting post over here about this, in relation to cross-application flow

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.