convertFromUIImageToStruct

Converting from UIImage/CGImage to Leptonica Pix structure
UIImage *image = [UIImage imageNamed:@"test.png"];
...
CFDataRef imageData = CGDataProviderCopyData(CGImageGetDataProvider([image CGImage]));
const UInt8 *rasterData = CFDataGetBytePtr(data);

/*-------------------------------------------------------------------------*
* Basic 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 */
};

UIImage *image = [UIImage imageNamed:@"test.png"];

CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider([image CGImage]));
const UInt8 *imageData = CFDataGetBytePtr(data);

Pix *myPix = (Pix *) malloc(sizeof(Pix));

CGImageRef myCGImage = [image CGImage];

myPix->w = CGImageGetWidth (myCGImage);
myPix->h = CGImageGetHeight (myCGImage);
myPix->d = CGImageGetBitsPerComponent(myCGImage);
myPix->wpl = CGImageGetBytesPerRow (myCGImage) / 4;
myPix->data = (l_uint32 *) imageData;
myPix->colormap = NULL;

NSLog(@"pixWrite=%d", pixWrite("/tmp/lept-res.bmp", myPix, IFF_BMP));

CGImageRef myCGImage = [image CGImage];
struct Pix myPix;
myPix.w = CGImageGetWidth (myCGImage);
myPix.h = CGImageGetHeight (myCGImage);
myPix.d = CGImageGetBitsPerComponent (myCGImage);
myPix.wpl = CGImageGetBytesPerRow (myCGImage) / 4;
... etc. ...

CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider([picture CGImage]));
const UInt8 *imageData = CFDataGetBytePtr(data);

Pix *myPix = (Pix *) malloc(sizeof(Pix));
CGImageRef myCGImage = [picture CGImage];

myPix->w = CGImageGetWidth (myCGImage);
myPix->h = CGImageGetHeight (myCGImage);
myPix->d = CGImageGetBitsPerPixel([picture CGImage]) ;
myPix->wpl = CGImageGetBytesPerRow (myCGImage)/4 ;
myPix->data = (l_uint32 *) imageData;
myPix->colormap = NULL;

pixEndianByteSwap(myPix);

NSLog(@"pixWrite=%d", pixWrite("/tmp/lept-res.bmp", myPix, IFF_BMP));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值