Dr.Hell 5 Report post Posted May 16, 2011 (edited) Здравствуйте! Программа на Borland Builder. Есть hDC компонента, нужно его изображение скопировать в IplImage. То есть, необходима функция обратная APIDrawIpl. Понятно, что скорее всего нужно аналогично побитово скопировать Bitmap в ImageData (хотя, тоже не очень понятно, как это сделать). Но может быть, есть какой-то более быстрый и легкий путь в эту сторону? Нашел вот эту тему: http://www.compvision.ru/forum/index.php?showtopic=390 Но, честно говоря, не понял, какое решение в итоге рабочее. Edited May 16, 2011 by Dr.Hell Share this post Link to post Share on other sites
Smorodov 578 Report post Posted May 17, 2011 Еще полезная ссылка в тему: http://wladm.narod.ru/Borland/graphicksborlandbmp.html Share this post Link to post Share on other sites
Dr.Hell 5 Report post Posted May 17, 2011 Спасибо! =) Оказалось, все вообще элементарно! И, главное, работает просто молниеносно, что мне и было необходимо! IplImage * TBitmapToIplImage(Graphics::TBitmap *src) { int _h = src->Height; int _w = src->Width; if (!src || _w==0) return NULL; IplImage* dest = cvCreateImage(cvSize(_w,_h),IPL_DEPTH_8U,3); try { unsigned char *pLine; for(int y=0; y<_h; y++) { pLine = (unsigned char *)src->ScanLine[y]; memcpy(dest->imageData+_w*3*y, pLine, _w*3); } } catch(...) { MessageBox(0,"Exception when get data ","Error", MB_OK ); } return dest; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Graphics::TBitmap* Bitmap = new Graphics::TBitmap; HDC DC=GetDC(0); // Делаем снимок экрана для примера, тут можно использовать любой DC try{ Bitmap->Height=Screen->Height; Bitmap->Width=Screen->Width; Bitmap->PixelFormat=pf24bit; // Обязательно нужно перевести в 24 бита // Копируем DC в битмап BitBlt(Bitmap->Canvas->Handle, 0, 0, Screen->Width, Screen->Height,DC, 0, 0, SRCCOPY); IplImage* TestImage = TBitmapToIplImage(Bitmap); APIDrawIpl(0,0,TestImage,Form1->Handle); } __finally { delete Bitmap; ReleaseDC(0,DC); } } 1 Share this post Link to post Share on other sites