Question

Currently, I loop the Canvas.Pixels[] property and read each pixel on a canvas to swap Red/Blue bytes around (for specific reasons). However, it takes an average of 2 seconds per picture, and I have over 8,000 pictures I need to convert (overnight). I understand I can use a method of ScanLine to accomplish this much faster, but I know nothing about ScanLine - it's a much lower level of coding than I'm comfortable with. What's the fastest way to accomplish this? I'm willing to wait some time for this to run through, but it would still be nice if I could chop that time in half or more.

Right now, this is the procedure I use:

procedure SwapBytes(var Bmp: TBitmap);
var
  X, Y: Integer;
  R, G, B: Byte;
  C: TColor;
begin
  for Y := 0 to Bmp.Height - 1 do begin
    for X := 0 to Bmp.Width - 1 do begin
      C:= Bmp.Canvas.Pixels[X,Y];
      R:= GetRValue(C);
      G:= GetGValue(C);
      B:= GetBValue(C);
      Bmp.Canvas.Pixels[X,Y]:= RGB(B, G, R)
    end;
  end;
end;

Added Note: An initial conversion of over 8,000 images is the first step of why I need this. However, I also will be using the same thing in our software to automatically convert any image on the spot, as needed. So a third-party converter won't work, because I cannot distribute this to our clients.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top