2012-08-03 61 views
0

我想从UIImage创建PIX数据结构。 PIX的结构:从UIImage创建Leptonica 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中执行此操作?

回答

0

您可以创建一个CGBitmapContext并在其中绘制图像。您需要使用RGB颜色空间来创建上下文。您可能需要在bitmapInfo参数中尝试使用kCGBitmapByteOrder32LittlekCGBitmapByteOrder32Big以获取正确顺序的R,G和B组件。

然后,您可以使用CGBitmapContextGetWidth,CGBitmapContextGetBytesPerRowCGBitmapContextGetData等功能,初始化您的struct Pixxres,yres,informat,textcolormap元素不对应于CGBitmapContextUIImage的任何属性,因此您应该将它们设置为0或NULL。

请看CGBitmapContext Reference以获取CGBitmapContext的帮助。

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

+0

不幸的是(对你而言),我对Leptonica一无所知。基于我对Core Graphics,C编程语言以及问题中的'struct'定义的了解,我能够回答这个问题。 – 2013-06-15 00:53:44

+0

好的,谢谢你的回复。非常感激! – Teddy13 2013-06-15 01:14:55

0

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

+0

嘿大卫,我想知道你能不能帮我一个忙,帮我一个忙吗?我一直在努力工作数天。看起来你知道你在做什么,我真的很感激它。非常感谢你,真的意味着很多。 stackoverflow.com/questions/17096618/leptonica-apply-threshold – Teddy13 2013-06-15 01:14:38