获取UIImage像素数据
来源:互联网 发布:恐怖黎明物品数据库 编辑:程序博客网 时间:2024/06/06 00:35
typedef CF_ENUM(uint32_t, CGImageAlphaInfo) {
kCGImageAlphaNone, /* For example, RGB. */
kCGImageAlphaPremultipliedLast, /* For example, premultiplied RGBA */
kCGImageAlphaPremultipliedFirst, /* For example, premultiplied ARGB */
kCGImageAlphaLast, /* For example, non-premultiplied RGBA */
kCGImageAlphaFirst, /* For example, non-premultiplied ARGB */
kCGImageAlphaNoneSkipLast, /* For example, RBGX. */
kCGImageAlphaNoneSkipFirst, /* For example, XRGB. */
kCGImageAlphaOnly /* No color data, alpha data only */
};
//Create a bitmap context
CG_EXTERN CGContextRef CGBitmapContextCreate(
void *data,//如果data非空,指向一个内存区域,大小至少bytesPerRow *height的字节。如果data为空,data上下文自动分配和释放收回。
size_t width,//像素宽
size_t height,//像素高
size_t bitsPerComponent, //位的数量为每个组件的指定一个像素
size_t bytesPerRow,//每一行的位图的字节,至少要宽*每个像素的字节
CGColorSpaceRef space, //指定一个颜色空间
CGBitmapInfo bitmapInfo//指定位图是否应该包含一个alpha通道和它是如何产生的,以及是否组件是浮点或整数
)
//获取UIImage像素ARGB值
- (unsigned char *)getImageData:(UIImage*)image
{
CGImageRef imageref = [image CGImage];
CGColorSpaceRef colorspace=CGColorSpaceCreateDeviceRGB();
int width=CGImageGetWidth(imageref);
int height=CGImageGetHeight(imageref);
int bytesPerPixel=4;
int bytesPerRow=bytesPerPixel*width;
int bitsPerComponent = 8;
unsigned char * imagedata=malloc(width*height*bytesPerPixel);
CGContextRef cgcnt =CGBitmapContextCreate(imagedata,
width,
height,
bitsPerComponent,
bytesPerRow,
colorspace,
kCGImageAlphaPremultipliedFirst);
//将图像写入一个矩形
CGRect therect = CGRectMake(0, 0, width, height);
CGContextDrawImage(cgcnt, therect, imageref);
//释放资源
CGColorSpaceRelease(colorspace);
CGContextRelease(cgcnt);
for (int i = 0 ; i < 4*width*height; i++) {
NSLog(@"UIImage(%d,%d) == %d",(i/4)%width,(i/4)/width,imagedata[i]);
if (i%4==3) {
NSLog(@"=================");
}
}
return imagedata;
}
//获取UIImage像素Gray值
- (unsigned char *)getImageData:(UIImage*)image
{
CGImageRef imageref = [image CGImage];
CGColorSpaceRef colorspace=CGColorSpaceCreateDeviceGray();
int width=CGImageGetWidth(imageref);
int height=CGImageGetHeight(imageref);
int bytesPerPixel=1;
int bytesPerRow=bytesPerPixel*width;
int bitsPerComponent = 8;
unsigned char * imagedata=malloc(width*height*bytesPerPixel);
CGContextRef cgcnt = CGBitmapContextCreate(imagedata,
width,
height,
bitsPerComponent,
bytesPerRow,
colorspace,
kCGImageAlphaNone);
//将图像写入一个矩形
CGRect therect = CGRectMake(0, 0, width, height);
CGContextDrawImage(cgcnt, therect, imageref);
//释放资源
CGColorSpaceRelease(colorspace);
CGContextRelease(cgcnt);
for (int i = 0 ; i < width*height; i++) {
NSLog(@"UIImage(%d,%d) == %d", i%width, i/width, imagedata[i]);
}
return imagedata;
}
- 获取UIImage像素数据
- ios 获取UIImage图片的像素尺寸
- 如何从UIImage或者CGImage获取到图片的像素数据
- uiimage 转换为像素数据 以及从像素数据生成为uiimage
- uiimage 转换为像素数据 以及从像素数据生成为uiimage
- objective-c中如何从UIImage中获取像素信息
- ios生成的UIimage获取img像素信息
- UIImage 读取修改像素颜色
- cocos2dx lua图片获取像素数据
- iOS 获取屏幕分辨率 以及放大模式、高清模式区别 和 获取UIImage图片的像素尺寸
- [IOS 开发] UIImage改变像素值
- 获取渐变的UIImage
- UIImage获取灰度图像
- VS2008中如何批量注释 图像像素数据获取
- 获取UIImage的图像MD5
- js获取屏幕像素
- 获取文件像素值
- 从位图获取像素
- 如何使用strace+pstack利器分析程序性能
- Android代码获取CPU运行情况
- 引起运动神经元损伤的原因
- 全自动软化水设备:全自动软化水设备工作流程解析
- python(4)date
- 获取UIImage像素数据
- opencv图像处理(1.Visual C++6.0 MFC的使用)
- java 必读经典书籍
- split 分割 字符串(分隔符如:* ^ : | , .) 及注意点
- DNS出现故障问题 解决方法
- HDU(1015)____Safecracker
- 小儿格林巴利综合症如何预防呢
- 解决Eclipse Debug 的source not found问题
- 如何让 Qt 的程序正确使用 Sleep .