Just wondering if someone can tell me what I'm doing wrong here, I just can't seem to work this out, I keep getting errors.

function GetColorFromBmp(XX, YY: Integer; Bmp: TBitmap): TColor;
var
  Line: PRGB32Array;
begin
  Line := Bmp.ScanLine[YY];
  Result := RGBtoColor(Line^[XX].R, Line^[XX].G, Line^[XX].B);
end;

procedure SetColorOnBmp(XX, YY: Integer; Color: TColor; Bmp: TBitmap);
var
  Line: PRGB32Array;
begin
  Line := Bmp.ScanLine[YY];
  Line^[XX].R := GetRValue(Color);
  Line^[XX].G := GetGValue(Color);
  Line^[XX].B := GetBValue(Color);
end;

What are the errors ?

What are the errors ?

Access violation errors. I don't really understand pointers all that well, I don't think I'm doing it properly.

I've figured it out, no need to worry, it was due to me not having declared the TRGB32Array variable type properly. Instead, now I'm using the TRGBTripleArray and pRGBTripleArray types, which are declared like so:

const
  PixelCountMax = 32768;

type
  TRGBTripleArray = array[0..PixelCountMax-1] of TRGBTriple;
  pRGBTripleArray = ^TRGBTripleArray;

I also needed to set the Bitmap PixelFormat's properly before trying to use ScanLine. I also found that I don't need to use the ^ character to refer to what the pointer points to, Delphi seems to do it automatically.

Double post, sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.