2012-08-03 59 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