Delphi-OpenCV/source/ocv.fmxutils.pas
Laentir Valetov 10f45d4f40 Fixed #82, #83
Signed-off-by: Laentir Valetov <laex@bk.ru>
2017-09-07 14:48:30 +04:00

61 lines
1.6 KiB
ObjectPascal

unit ocv.fmxutils;
interface
Uses
ocv.core.types_c,
FMX.Graphics;
procedure IPLImageToFMXBitmap(const IpImage: pIplImage; const FMXBitmap: TBitmap); inline;
implementation
Uses FMX.Types;
procedure IPLImageToFMXBitmap(const IpImage: pIplImage; const FMXBitmap: TBitmap); inline;
Var
BitmapData: TBitmapData;
i: Integer;
SrcData, DestData: pByte;
nC: Integer;
pf: Integer;
begin
SrcData := nil;
Assert(Assigned(IpImage) and Assigned(FMXBitmap));
if (IpImage^.Width > 0) and (IpImage^.Height > 0) and Assigned(IpImage^.imageData) then
try
nC := IpImage^.nChannels;
With IpImage^ do
begin
SrcData := AllocMem(Width * Height * nC);
Move(imageData^, SrcData^, Width * Height * nC);
end;
// FMXBitmap.Canvas.BeginScene;
// try
if (FMXBitmap.Width <> IpImage^.Width) or (FMXBitmap.Height <> IpImage^.Height) then
FMXBitmap.SetSize(IpImage^.Width, IpImage^.Height);
if FMXBitmap.Map(TMapAccess.Write, BitmapData) then
try
DestData := pByte(BitmapData.Data);
pf := PixelFormatBytes[FMXBitmap.PixelFormat];
for i := 0 to BitmapData.Width * BitmapData.Height - 1 do
begin
DestData[i * pf + 0] := SrcData[i * nC + 0];
DestData[i * pf + 1] := SrcData[i * nC + 1];
DestData[i * pf + 2] := SrcData[i * nC + 2];
DestData[i * pf + 3] := $FF;
end;
finally
FMXBitmap.Unmap(BitmapData);
end;
// finally
// FMXBitmap.Canvas.EndScene;
// end;
finally
if Assigned(SrcData) then
FreeMem(SrcData);
end;
end;
end.