獲取圖片像素點顏色值

- (void*)getImageData:(UIImage*)image 
{ 
    void* imageData; 
    if (imageData == NULL)  
        imageData = malloc(4 * image.size.width * image.size.height); 
     
    CGColorSpaceRef cref = CGColorSpaceCreateDeviceRGB(); 
    CGContextRef gc = CGBitmapContextCreate(imageData, 
                                            image.size.width,image.size.height, 
                                            8,image.size.width*4, 
                                            cref,kCGImageAlphaPremultipliedFirst); 
    CGColorSpaceRelease(cref); 
    UIGraphicsPushContext(gc); 
     
    [image drawAtPoint:CGPointMake(0.0f, 0.0f)]; 
     
    UIGraphicsPopContext(); 
    CGContextRelease(gc); 
     
    return imageData; 
發佈了53 篇原創文章 · 獲贊 0 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章