IOS取图片的某个位置的像素(ARGB)
来源:互联网 发布:手机淘宝太费流量 编辑:程序博客网 时间:2024/05/20 22:41
//
// cUIImageData.h
// HelloWorld
//
// Created by apple on 13-10-3.
// Copyright (c) 2013年 apple. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef struct {
Byte A;
Byte R;
Byte G;
Byte B;
}Color;
@interface cUIImageData : NSObject
-(Byte*)getImageData:(UIImage*)Image;
-(Color)GetImageColorAtPointX:(int)X
PointY:(int)Y
FromImage:(Byte*)ImageData
OfImageSize:(CGSize)ImageSize;
@end
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// cUIImageData.m
// HelloWorld
//
// Created by apple on 13-10-3.
// Copyright (c) 2013年 apple. All rights reserved.
//
#import "cUIImageData.h"
@implementation cUIImageData
//将UIimage中的数据放入Byte数组中,顺序为ARGB.
-(Byte*)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;
void* imageData ;//准备用来存储数据的数组
CGContextRef cgContexRef = CGBitmapContextCreate(NULL,
width,
height,
//
//
//
//
//
//
#import <Foundation/Foundation.h>
typedef struct {
}Color;
@interface cUIImageData : NSObject
-(Byte*)getImageData:(UIImage*)Image;
-(Color)GetImageColorAtPointX:(int)X
@end
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//
//
//
//
//
//
#import "cUIImageData.h"
@implementation cUIImageData
//将UIimage中的数据放入Byte数组中,顺序为ARGB.
-(Byte*)getImageData:(UIImage*)Image{