从UIImage创建Leptonica PIX结构 [英] Create Leptonica PIX struct from UIImage

查看:84
本文介绍了从UIImage创建Leptonica PIX结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to create a PIX data structure from a UIImage. The struct of 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中执行此操作?

How can I do this in iOS?

推荐答案

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

You can create a CGBitmapContext and draw the image into it. You need to use the RGB color space to create the context. You may need to experiment with kCGBitmapByteOrder32Little and kCGBitmapByteOrder32Big in the bitmapInfo argument to get the R, G, and B components in the correct order.

然后,您可以初始化 struct Pix 然后,使用 CGBitmapContextGetWidth CGBitmapContextGetBytesPerRow CGBitmapContextGetData xres yres informat text colormap 元素与 CGBitmapContext 的任何属性都不对应,或者 UIImage ,因此您应该将它们设置为0或NULL。

Then you can initialize your struct Pix from that, using functions like CGBitmapContextGetWidth, CGBitmapContextGetBytesPerRow, and CGBitmapContextGetData. The xres, yres, informat, text, and colormap elements don't correspond to any attributes of CGBitmapContext or UIImage, so you should probably set them to 0 or NULL.

看看 CGBitmapContext参考 CGBitmapContext 的帮助。

也请查看 Quartz 2D编程指南 帮助创建位图上下文,以及帮助将图像绘制到上下文中。

Also look at the Quartz 2D Programming Guide for help creating a bitmap context, and for help drawing your image into the context.

这篇关于从UIImage创建Leptonica PIX结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆