Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you tell me how to implement the method of "BitmapToIplImage8U" #1

Open
zeizeizhu opened this issue Sep 24, 2017 · 1 comment

Comments

@zeizeizhu
Copy link

zeizeizhu commented Sep 24, 2017

please show me the implementation of the method "BitmapToIplImage8U". I has a project about twain that need to convert bmp to iplimage too. Could you tell me how to implement it.

@mrlitong
Copy link
Owner

mrlitong commented Sep 26, 2017

Here is a code snippets,TEST it yourself.

IplImage* GetIplImage(Bitmap^ bitmap)
{
   Drawing::Imaging::BitmapData^ bitmapData;
   IplImage* pimg=cvCreateImage(cvSize(bitmap->Width, bitmap->Height), IPL_DEPTH_8U, 3);
   bitmapData = bitmap->LockBits(
     Drawing::Rectangle(0, 0, bitmap->Width, bitmap->Height),
     Drawing::Imaging::ImageLockMode::ReadOnly,
     Drawing::Imaging::PixelFormat::Format24bppRgb
     );
  memcpy(pimg->imageData, bitmapData->Scan0.ToPointer(), pimg->imageSize);
  pimg->imageDataOrigin = NULL;
  pimg->imageId = NULL;
  pimg->maskROI = NULL;
  pimg->roi = NULL;
  bitmap->UnlockBits(bitmapData);
  delete [] bitmapData;
  delete(bitmap);
  return pimg;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants