{I+=codeWee;}
[C++] Gdiplus: Convert Bitmap to Byte array
void BitmapToBytes(Gdiplus::Bitmap* bmp, BYTE**	ppImageData)
{
	Gdiplus::Rect rect(0, 0, bmp->GetWidth(), bmp->GetHeight());
	//get the bitmap data
	Gdiplus::BitmapData bitmapData;
	if (Gdiplus::Ok == bmp->LockBits(
		&rect, //A rectangle structure that specifies the portion of the Bitmap to lock.
		Gdiplus::ImageLockModeRead | Gdiplus::ImageLockModeWrite, //ImageLockMode values that specifies the access level (read/write) for the Bitmap.            
		PixelFormat32bppARGB,// PixelFormat values that specifies the data format of the Bitmap.
		&bitmapData //BitmapData that will contain the information about the lock operation.
		))
	{
		//get the lenght of the bitmap data in bytes
		int len = bitmapData.Height * std::abs(bitmapData.Stride);
		if (*ppImageData)
		{
			delete[] * ppImageData;
		}
		*ppImageData = new BYTE[len];
		memcpy(*ppImageData, bitmapData.Scan0, len);//copy it to an array of BYTEs

		//... 

		//cleanup
		bmp->UnlockBits(&bitmapData);
	}
}
HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.