Opencv读取各种格式图片,在TBitmap上面重绘

    //opencv读取图片
    cv::Mat image;
    //const char *fileName = "HeadImage-UI/Photo-001.bmp";
    const char *fileName = "HeadImage-UI/53d253192be47412.jpg!200x200.jpg";

    image = cv::imread(fileName);

    //bitmap冲回image
    Graphics::TBitmap *bitmap = new Graphics::TBitmap;
    bitmap->PixelFormat = pf24bit;
    bitmap->Height = image.rows;
    bitmap->Width = image.cols;
    for(int y=0;y<bitmap->Height;y++)
    {
        uchar *ptr = image.ptr<uchar>(y);
        Byte *p=(Byte*)bitmap->ScanLine[y];
        for(int x=0;x<bitmap->Width;x++)
        {
            p[0] = ptr[0];
            p[1] = ptr[1];
            p[2] = ptr[2];
            p+=3;
            ptr+=3;
        }
    }
    Image1->Picture->Bitmap = bitmap;

 

posted @ 2016-01-07 15:28  一样菜  阅读(940)  评论(0编辑  收藏  举报