mirror of
https://github.com/Laex/Delphi-OpenCV.git
synced 2024-11-15 15:55:53 +01:00
10f45d4f40
Signed-off-by: Laentir Valetov <laex@bk.ru>
61 lines
1.6 KiB
ObjectPascal
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.
|