我想从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中做到这一点?
发布于 2012-08-04 01:26:21
您可以创建一个CGBitmapContext并将图像绘制到其中。您需要使用RGB颜色空间来创建上下文。您可能需要在bitmapInfo参数中试验kCGBitmapByteOrder32Little和kCGBitmapByteOrder32Big,以便以正确的顺序获得R、G和B组件。
然后,您可以使用CGBitmapContextGetWidth、CGBitmapContextGetBytesPerRow和CGBitmapContextGetData等函数在此基础上初始化struct Pix。xres、yres、informat、text和colormap元素并不对应于CGBitmapContext或UIImage的任何属性,因此您可能应该将它们设置为0或NULL。
有关CGBitmapContext的帮助,请查看。
另请查看,以获得创建位图上下文的帮助,以及将图像绘制到上下文中的帮助。
发布于 2012-08-04 01:21:00
您将从一个UIImage开始,然后使用"CGImage“从它获得一个CGImageRef。使用CGImageRef,您可以查询它的宽度、高度、深度和wpl (您将从图像中获得bytesPerRow,然后除以像素大小进行修改)。要获取将其呈现到上下文中所需的数据,请获取该点,然后将该数据复制到NSData对象中。大小将是bytesPerRow值的行数。
https://stackoverflow.com/questions/11800177
复制相似问题