繁体   English   中英

在C中将图像转换为可用的字节数组?

[英]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;
    }

我让我的学生使用netpbm来表示图像,因为它带有一个方便的C库,但您也可以将图像放入文本形式,手工创建,等等。 这里的好处是你可以使用Unix方式的命令行工具将各种图像(而不仅仅是JPEG)转换为PBM格式。 djpeg工具可用于许多地方,包括JPEG俱乐部 经验相对较少的学生可以使用这种格式编写一些相当复杂的程序。

OpenCV也可以这样做。

http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/index.html

搜索:“访问图像元素”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM