0

Ok, so, as title says I'm having some issues while converting UnsafeMutableBufferPointer to NSData(using Swift). I have tried pretty much noting since I have no idea. Can, please, someone help me out figure out how can I do that? EDIT: Here I have some code to show you how do i get bits from an Image.

private static func getBitesFromImage(image: UIImage) -> UnsafeMutableBufferPointer<Bit> {
    let dataImage = UIImagePNGRepresentation(image)
    let ptr = UnsafeMutablePointer<Bit>(dataImage!.bytes)
    let bites = UnsafeMutableBufferPointer<Bit>(start:ptr, count:dataImage!.length * 8)
    return bites
}
  • Do you really mean "bit" and not "byte"? Where does the pointer come from? Some context would be helpful. – Martin R Mar 05 '16 at 18:17
  • Yup, i mean BIT. I have an image and I want it binary. I will put some code in a sec – Alexandru Firtulescu Mar 05 '16 at 18:22
  • I am afraid that you are complete on a wrong track :) UIImagePNGRepresentation() gives you the image data in the PNG file format (which is a sequence of *bytes*). It does not give you access to the raw pixel data. – `Bit` is a Swift type representing "Zero" and "One", but it consumes a *byte*, and you cannot simply cast the UInt8 pointer `dataImage!.bytes` to a `Bit` pointer. – Have a look e.g. at http://stackoverflow.com/questions/25146557/how-do-i-get-the-color-of-a-pixel-in-a-uiimage-with-swift how to access the pixel data of an UIImage. – Martin R Mar 05 '16 at 18:34
  • Oh, actually I have to do a steganography app and I need to get Bites so I can modify them. I guess that thread is not helping me. I will try and find some other solutions – Alexandru Firtulescu Mar 06 '16 at 11:00

1 Answers1

0

As per the comments, Bit is a single bit representing 1 or 0, so this is down the wrong track.

UIImagePNGRRepresentation already returns you an NSData with it's .bytes property

Orion Edwards
  • 121,657
  • 64
  • 239
  • 328