从UIImage创buildLeptonica PIX结构
我想从UIImage创build一个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中做到这一点?
您可以创build一个CGBitmapContext
并将图像绘制到其中。 您需要使用RGB颜色空间来创build上下文。 您可能需要在bitmapInfo
参数中尝试使用kCGBitmapByteOrder32Little
和kCGBitmapByteOrder32Big
来获取正确顺序的R,G和B组件。
然后你可以使用像CGBitmapContextGetWidth
, CGBitmapContextGetBytesPerRow
和CGBitmapContextGetData
这样的函数来初始化你的struct Pix
。 xres
, yres
, informat
, text
和colormap
元素不对应于CGBitmapContext
或UIImage
任何属性,所以你应该把它们设置为0或NULL。
看一下CGBitmapContext参考来获取关于CGBitmapContext
帮助。
另外请看Quartz 2D Programming Guide来帮助创build位图上下文,并帮助您将图像绘制到上下文中。
你将从一个UIImage开始,然后使用“CGImage”从那里获得一个CGImageRef。 使用CGImageRef,你可以查询它的宽度,高度,深度,wpl(你将从图像中获得bytesPerRow,然后通过除以像素大小进行修改)。 要获取数据,需要将其渲染到上下文中,获取该点,然后将该数据复制到NSData对象中。 大小将是bytesPerRow值的行数。
- 在iOS中使用drawRect和drawLayerInContext呈现PDF
- SceneKit剔除飞机
- 预渲染的核心graphicsanimation不会顺利地animation和内存
- iOS:逆UIBezierPath(bezierPathWithOvalInRect)
- iOS – 这是更好的select把图像? 核心graphics(PaintCode应用程序)与图像文件(PNG)
- 如何在两个单独的图层上绘制iOS,coregraphics
- 如何find箭头提示点,给出一条线的起点和终点
- EXC_BAD_ACCESS,同时使用CoreAnimation
- CGAffineTransformMakeRotation在外部点附近