[英]Convert image into useable byte array in C?
有谁知道如何在C或C ++中打开图像,特别是jpg到字节数组? 任何形式的帮助表示赞赏。
谢谢!
ImageMagick库也可以这样做,虽然它经常提供足够的图像处理功能,你可以做很多事情而不需要将图像转换为字节数组并自己处理它。
您可以尝试DevIL图像库我只使用它与OpenGL相关的东西,但它也只是一个普通的图像加载库。
在wxWidgets GUI Framework中查看wxImage的源代码。 您很可能对* nix发行版感兴趣。
另一种选择是GNU Jpeg库。
以下是使用标头GdiPlusBitmap.h中定义的GDIPlus Bitmap.LockBits方法的方法:
Gdiplus::BitmapData bitmapData;
Gdiplus::Rect rect(0, 0, bitmap.GetWidth(), bitmap.GetHeight());
//get the bitmap data
if(Gdiplus::Ok == bitmap.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.
bitmap.GetPixelFormat(),// 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);
BYTE* buffer = new BYTE[len];
memcpy(bitmapData.Scan0, buffer, len);//copy it to an array of BYTEs
//...
//cleanup
pBitmapImageRot.UnlockBits(&bitmapData);
delete []buffer;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.