Creating UIImage from raw RGBA data

后端 未结 3 1380
夕颜
夕颜 2020-12-09 04:53

I have been trying to convert an array RGBA data (int bytes) into a UIImage. My code looks like as follows:

/*height and width are integers denoting the dime         


        
相关标签:
3条回答
  • 2020-12-09 05:20

    I just independently verified this problem, I think it should be reported as a bug to Apple. +(UIImage)imageWithCGImage: doesn't properly transfer the width and height of the source CGImageRef to the UIImage.

    0 讨论(0)
  • 2020-12-09 05:40

    The problem is solved now. I get the image that I want displayed but still unable to figure out why the width and height are different. Essentially nothing wrong with the program per say. The only problem being width and height.

    0 讨论(0)
  • 2020-12-09 05:47

    It turns out the problem is a pretty silly mistake that both of us overlooked. UIImage dimensions are stored as floats, not integers. :D

    Try

    NSLog(@"resultImg width:%f, height:%f",
              newImage.size.width,newImage.size.height);
    

    Instead. The image size has been transferred correctly.

    0 讨论(0)
提交回复
热议问题