Ok, ive just begun a new project the other day, and have been working out how to implement some effects features. Using some online sample code the below function can invert the colours of a bitmap in a TImage. Works fine too:

function InvertBitmap(MyBitmap: TBitmap): TBitmap;
var
x, y: Integer;
ByteArray: PByteArray;
begin
MyBitmap.PixelFormat := pf24Bit;
for y := 0 to MyBitmap.Height - 1 do
begin
ByteArray := MyBitmap.ScanLine[y];
for x := 0 to MyBitmap.Width * 3 - 1 do
begin
ByteArray[x] := 255 - ByteArray[x];
end;
end;
Result := MyBitmap;
end;

imgMain.Picture.Bitmap := InvertBitmap(imgMain.Picture.Bitmap);
imgMain.Refresh;


Problem: Im not using a TImage control but an external component which handles more filetypes, such as JPG. Because of this, the above function will only invert the image if its a bitmap, any other file type is converted to white.

Question: How can i invert ANY image type?

My idea was to convert the image, say JPG to BMP, invert it, then convert it back. But it seems a lot of hassle for just inverting an image.

Appreciate any help or solutions to such an easy problem