Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. let bitsPerComponent = 8
  2. let bitsPerPixel = bitsPerComponent * 4
  3. let bytesPerRow = bitsPerPixel * width / 8
  4.  
  5. let providerRef = CGDataProvider(
  6. data: NSData(bytes: pixels, length: height * width * 4) //Do not put `&` as pixels is already an `UnsafePointer`
  7. )
  8. //let provider: CGDataProvider! = CGDataProvider(data: cfdata)
  9. /*if provider == nil {
  10. print("CGDataProvider is not supposed to be nil")
  11. return nil
  12. }*/
  13.  
  14. let cgimage = CGImage(
  15. width: width,
  16. height: height,
  17. bitsPerComponent: bitsPerComponent,
  18. bitsPerPixel: bitsPerPixel,
  19. bytesPerRow: bytesPerRow,
  20. space: CGColorSpaceCreateDeviceRGB(),
  21. bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedFirst.rawValue),
  22. provider: providerRef!,
  23. decode: nil,
  24. shouldInterpolate: true,
  25. intent: .defaultIntent
  26. )
  27.  
  28. if cgimage == nil {
  29. print("CGImage is not supposed to be nil")
  30. return nil
  31. }
  32. return UIImage(cgImage: cgimage!)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement