C# bitmap 灰度图像 Pattle 问题

问题描述:在C#中使用Bitmap创建灰度图像时,创建出的图像为伪彩色图像,主要是因为pattle的问题,解决方案如下代码所示:

Bitmap^ LBP::ConvertIplImageToBmp(IplImage* img)
	{
		if (img == nullptr)
			return nullptr;

		if (img->nChannels != 1)		// 只处理单通道图像
			return nullptr;

		IntPtr ptr = IntPtr(img->imageData);
		//_lbpBmp = gcnew Bitmap(img->width, img->height, PixelFormat::Format8bppIndexed, ptr);
		_lbpBmp = gcnew Bitmap(img->width, img->height, img->widthStep, PixelFormat::Format8bppIndexed, ptr);

		ColorPalette^ palette = _lbpBmp->Palette;
		for (int i = 0; i < 256; ++i)
		{
			palette->Entries[i] = Color::FromArgb(255, i, i, i);
		}
		_lbpBmp->Palette = palette;

		_lbpBmp->Save("lbp.bmp", ImageFormat::Bmp);
		return _lbpBmp;
}


猜你喜欢

转载自blog.csdn.net/lingtianyulong/article/details/77926192
今日推荐