博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
convertFromUIImageToStruct
阅读量:6537 次
发布时间:2019-06-24

本文共 2430 字,大约阅读时间需要 8 分钟。

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));

转载于:https://www.cnblogs.com/pengyingh/articles/2488213.html

你可能感兴趣的文章
CentOS 6/7 共享文件目录
查看>>
Dubbo源码之服务端并发控制——ExecuteLimitFilter
查看>>
ant
查看>>
设计模式 - 生产者/消费者模式
查看>>
CentOS搭建NodeJS+GitHub基础开发环境
查看>>
微信,想要说爱你,却没有那么容易!
查看>>
浅谈AngularJS--基础
查看>>
有关sqlite与sql
查看>>
MapXtreme 2005 学习心得 概述(一)
查看>>
php进一法取整、四舍五入取整、忽略小数等的取整数方法大全
查看>>
Hibernate的拦截器和监听器
查看>>
游戏中学习Bash技能
查看>>
ubuntu 12.04系统托盘不显示ibus输入法图标的解决方法
查看>>
垂直分区和水平分区
查看>>
Tomcat LimitLatch
查看>>
WSDP
查看>>
Angularjs checkbox ng-true-value不支持中文
查看>>
Memory Management
查看>>
The Packaging Process in Yocto/OE
查看>>
golang--Redis最佳的Go语言驱动
查看>>