0

我想从 UIImage 创建一个 PIX 数据结构。PIX的结构:

struct Pix
{
     l_uint32             w;           /* width in pixels                   */
     l_uint32             h;           /* height in pixels                  */
     l_uint32             d;           /* depth in bits                     */
     l_uint32             wpl;         /* 32-bit words/line                 */
     l_uint32             refcount;    /* reference count (1 if no clones)  */
     l_int32              xres;        /* image res (ppi) in x direction    */
                                       /* (use 0 if unknown)                */
     l_int32              yres;        /* image res (ppi) in y direction    */
                                       /* (use 0 if unknown)                */
     l_int32              informat;    /* input file format, IFF_*          */
     char                *text;        /* text string associated with pix   */
     struct PixColormap  *colormap;    /* colormap (may be null)            */
     l_uint32            *data;        /* the image data                    */
 };
 typedef struct Pix PIX;


struct PixColormap
 {
     void            *array;     /* colormap table (array of RGBA_QUAD)     */
     l_int32          depth;     /* of pix (1, 2, 4 or 8 bpp)               */
     l_int32          nalloc;    /* number of color entries allocated       */
     l_int32          n;         /* number of color entries used            */
};

我怎样才能在 iOS 中做到这一点?

4

2 回答 2

0

您将从 UIImage 开始,然后使用“CGImage”从中获取 CGImageRef。使用 CGImageRef,您可以查询它的宽度、高度、深度、wpl(您将从图像中获得 bytesPerRow,然后通过除以像素大小进行修改)。要获取您需要将其呈现到上下文中的数据,请获取要点,然后将该数据复制到 NSData 对象中。大小将是按 bytesPerRow 值计算的行数。

于 2012-08-03T17:20:59.927 回答
0

您可以创建一个CGBitmapContext并将图像绘制到其中。您需要使用 RGB 颜色空间来创建上下文。您可能需要在参数中试验kCGBitmapByteOrder32Little并以正确的顺序获取 R、G 和 B 分量。kCGBitmapByteOrder32BigbitmapInfo

然后,您可以struct Pix使用 、 和 等函数CGBitmapContextGetWidthCGBitmapContextGetBytesPerRow初始化您的CGBitmapContextGetData。、xresyresinformat和元素不对应于or的任何属性text,因此您可能应该将它们设置为 0 或 NULL。colormapCGBitmapContextUIImage

查看CGBitmapContext 参考以获取有关CGBitmapContext.

另请参阅Quartz 2D Programming Guide以获取创建位图上下文的帮助,以及将图像绘制到上下文中的帮助。

于 2012-08-03T17:26:20.930 回答