Jump to content
Compvision.ru
Sign in to follow this  
RinOS

APIDrawIpl на Delphi

Recommended Posts

IplImage To Bitmap;

Переделал функцию рисования IplImage для Delphi. Пользуйтесь ))

function WidthBytes(bits: Integer): Integer;

begin

Result := Trunc((bits + 31) / 32) * 4;

end;

function CreateRGBBitmap(Ipl: PIplImage): HBITMAP;

var

i, j: Integer;

LApp: PChar;

LBitInfo: TBitmapInfo;

begin

LBitInfo.bmiHeader.biSize := SizeOf(BITMAPINFOHEADER);

LBitInfo.bmiHeader.biWidth := Ipl.width;

LBitInfo.bmiHeader.biHeight := Ipl.height;

LBitInfo.bmiHeader.biPlanes := 1;

LBitInfo.bmiHeader.biBitCount := 24;

LBitInfo.bmiHeader.biCompression := BI_RGB;

LBitInfo.bmiHeader.biSizeImage := WidthBytes(Ipl.width * 8) * Ipl.height;

LBitInfo.bmiHeader.biXPelsPerMeter := 0;

LBitInfo.bmiHeader.biYPelsPerMeter := 0;

LBitInfo.bmiHeader.biClrUsed := 0;

LBitInfo.bmiHeader.biClrImportant := 0;

Result := CreateDIBSection(0, LBitInfo, DIB_RGB_COLORS, Pointer(LApp), 0, 0);

if(Ipl.nChannels = 1) then

for i := 0 to Ipl.height - 1 do

for j := 0 to Ipl.width - 1 do

begin

LApp[Ipl.width*3*(Ipl.height-i-1)+j*3] := Ipl.imageData[Ipl.width*(i)+j];

LApp[Ipl.width*3*(Ipl.height-i-1)+j*3+1] := Ipl.imageData[Ipl.width*(i)+j];

LApp[Ipl.width*3*(Ipl.height-i-1)+j*3+2] := Ipl.imageData[Ipl.width*(i)+j];

end;

if Ipl.nChannels = 3 then

for i := 0 to Ipl.height - 1 do

Move(Pointer(Ipl.imageData+Ipl.width*3*i)^,

Pointer(LApp+Ipl.width*3*(Ipl.height-i-1))^, Ipl.width*3);

end;

procedure APIDrawIpl(X, Y: Integer; Handle: THandle; Ipl: PIplImage);

var

LMemDC, LHDC: HDC;

LBitmap: HBITMAP;

begin

LHDC := GetDC(Handle);

LMemDC := CreateCompatibleDC(LHDC);

LBitmap := CreateRGBBitmap(Ipl);

SelectObject(LMemDC, LBitmap);

BitBlt(LHDC, X, Y, Ipl.width, Ipl.height, LMemDC, 0, 0, SRCCOPY);

DeleteObject(LBitmap);

DeleteDC(LMemDC);

DeleteDC(LHDC);

end;

  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×