UIimage转换为char * [英] UIimage to char* conversion

查看:124
本文介绍了UIimage转换为char *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将uiimage转换为char数组以与libtiff一起使用。



谢谢

解决方案

这是我所知道的最简单方法获取UIImage的字节:

  UIImage * someImage = ...; 
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(someImage.CGImage));
const UInt8 * data = CFDataGetBytePtr(pixelData);

数据则是一个字节数组。



<编辑:



以下是获取字符数组的方法:

  const unsigned char * buffer = CFDataGetBytePtr(pixelData); 

编辑2:



尝试投射它to char:

  char * buffer =(char *)CFDataGetBytePtr(pixelData); 


I am trying to convert uiimage to char array to use with libtiff.

Thanks

解决方案

Here is the easiest way that I know of to get the bytes of a UIImage:

UIImage *someImage = ...;
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(someImage.CGImage));
const UInt8 *data = CFDataGetBytePtr(pixelData);

Data then is an array of bytes.

EDIT:

Here is how you get an char array:

const unsigned char * buffer =  CFDataGetBytePtr(pixelData);

EDIT 2:

Try casting it to char:

char * buffer = (char *)CFDataGetBytePtr(pixelData);

这篇关于UIimage转换为char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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