2015-08-26 19:35:51 +02:00
|
|
|
unit ocv.fmxutils;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
Uses
|
|
|
|
ocv.core.types_c,
|
|
|
|
FMX.Graphics;
|
|
|
|
|
2017-05-24 17:27:25 +02:00
|
|
|
procedure IPLImageToFMXBitmap(const IpImage: pIplImage; const FMXBitmap: TBitmap); inline;
|
2015-08-26 19:35:51 +02:00
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
Uses FMX.Types;
|
|
|
|
|
2017-05-24 17:27:25 +02:00
|
|
|
procedure IPLImageToFMXBitmap(const IpImage: pIplImage; const FMXBitmap: TBitmap); inline;
|
2015-08-26 19:35:51 +02:00
|
|
|
Var
|
2017-05-24 17:27:25 +02:00
|
|
|
BitmapData: TBitmapData;
|
2015-08-26 19:35:51 +02:00
|
|
|
i: Integer;
|
|
|
|
SrcData, DestData: pByte;
|
|
|
|
nC: Integer;
|
2017-05-24 17:27:25 +02:00
|
|
|
pf: Integer;
|
2015-08-26 19:35:51 +02:00
|
|
|
begin
|
2017-09-07 12:38:44 +02:00
|
|
|
SrcData := nil;
|
2015-08-26 19:35:51 +02:00
|
|
|
Assert(Assigned(IpImage) and Assigned(FMXBitmap));
|
2017-05-24 17:27:25 +02:00
|
|
|
if (IpImage^.Width > 0) and (IpImage^.Height > 0) and Assigned(IpImage^.imageData) then
|
2015-08-26 19:35:51 +02:00
|
|
|
try
|
|
|
|
nC := IpImage^.nChannels;
|
2017-05-24 17:27:25 +02:00
|
|
|
With IpImage^ do
|
2015-08-26 19:35:51 +02:00
|
|
|
begin
|
2017-05-24 17:27:25 +02:00
|
|
|
SrcData := AllocMem(Width * Height * nC);
|
|
|
|
Move(imageData^, SrcData^, Width * Height * nC);
|
2015-08-26 19:35:51 +02:00
|
|
|
end;
|
2017-05-24 17:27:25 +02:00
|
|
|
// 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;
|
2015-08-26 19:35:51 +02:00
|
|
|
finally
|
2017-09-07 12:38:44 +02:00
|
|
|
if Assigned(SrcData) then
|
|
|
|
FreeMem(SrcData);
|
2015-08-26 19:35:51 +02:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|