- {}function LoadPictureImage(FileName : String) : PRGBAImage;
- {}
- {} var
- {} pic : TPicture; // picture object
- {} bmp : TBitMap; // bitmap graphics
- {} w,h : integer; // width and height of picture
- {} img : pRGBAImage;
- {} l,c : integer;
- {} hlp : byte;
- {}
- {} begin
- {} img := NIL;
- {} pic := TPicture.Create;
- {} bmp := TBitMap.Create;
- {} try
- {} pic.LoadFromFile(FileName);
- {} w := pic.Width;
- {} h := pic.Height;
- {}
- {} bmp.PixelFormat := pf32Bit;
- {} bmp.Width := w;
- {} bmp.Height := h;
- {} bmp.Canvas.Draw(0,0,pic.Graphic);
- {}
- {} new(img);
- {} with img^ do begin
- {} width := w;
- {} height := h;
- {} GetMem(data, w * h * SizeOf(TRGBA));
- {} for l := 0 to h-1 do
- {} Move(bmp.ScanLine[l]^, data^[l*w], w*4);
- {}
- {} // store rgba rather than bgra images
- {} for l := 0 to h-1 do
- {} for c := 0 to w-1 do with data[l*w+c] do begin
- {} hlp := r;
- {} r := b;
- {} b := hlp;
- {} a := not(a);
- {} end;
- {}
- {} end; // with
- {}
- {} finally
- {} pic.Free;
- {} bmp.Free;
- {} result := img;
- {} end;
- {}
- {} end;