Byte Array to UIImage Objective-C

前端 未结 1 1236
情书的邮戳
情书的邮戳 2021-01-07 03:30

I have a Bytearray

unsigned char *outputData = (unsigned char *)malloc(sizeof(unsigned char) * w * h * 4);

    outputData[y * h * 4 + x * 4 + 0] = all; //a         


        
相关标签:
1条回答
  • 2021-01-07 03:47
        CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB();
        CGContextRef bitmapContext=CGBitmapContextCreate(outputData, w, h, 8, 4*w, colorSpace,  kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault);
        CFRelease(colorSpace);
        free(outputData);
        CGImageRef cgImage=CGBitmapContextCreateImage(bitmapContext);
        CGContextRelease(bitmapContext);
    
        UIImage * newimage = [UIImage imageWithCGImage:cgImage];
        CGImageRelease(cgImage);
    
    0 讨论(0)
提交回复
热议问题