nsdata

Storing the data representations of multiple, differently typed objects in a single Data instance

假如想象 提交于 2021-02-10 17:50:21
问题 Motivation To my knowledge, Data is a struct that abstracts a byte buffer. It references a physical area in memory, in other words: a contiguous number of bytes. Now I want to efficiently store multiple values in memory (as raw data), where the values are not all of the same type . My definition of efficient here ≔ Store all those values without any unused buffer / gap bytes. Storing the raw data in memory let a: UInt8 = 39 let b: Int32 = -20001 let string: String = "How awesome is this data?

How do I convert a CVPixelBuffer / CVImageBuffer to Data?

五迷三道 提交于 2021-02-10 15:57:14
问题 My camera app captures a photo, enhances it in a certain way, and saves it. To do so, I get the input image from the camera in the form of a CVPixelBuffer (wrapped in a CMSampleBuffer). I perform some modifications on the pixel buffer, and I then want to convert it to a Data object. How do I do this? Note that I don't want to convert the pixel buffer / image buffer to a UIImage or CGImage since those don't have metadata (like EXIF). I need a Data object. How do I get one from a CVPixelBuffer

How do I convert a CVPixelBuffer / CVImageBuffer to Data?

南笙酒味 提交于 2021-02-10 15:55:12
问题 My camera app captures a photo, enhances it in a certain way, and saves it. To do so, I get the input image from the camera in the form of a CVPixelBuffer (wrapped in a CMSampleBuffer). I perform some modifications on the pixel buffer, and I then want to convert it to a Data object. How do I do this? Note that I don't want to convert the pixel buffer / image buffer to a UIImage or CGImage since those don't have metadata (like EXIF). I need a Data object. How do I get one from a CVPixelBuffer

Increasing Length of NSData

强颜欢笑 提交于 2021-02-07 19:54:46
问题 Basically, I have an NSString of 46 characters which i convert to NSData. I need to pad the string to 48 characters. It does not work via just adding ' ' to the end of the NSString. So, i just increased the length of NSData using this: NSString *string = @"__46characterlongstring__"; NSData *d = [string dataUsingEncoding:NSUTF8StringEncoding]; NSLog(@"d: %@", d); NSData *data = [NSData dataWithBytes:[d bytes] length:48]; NSLog(@"data: %@", data); The NSData called 'd' returns <723d6c67

Swift -How to know if a file was successfully saved in .cachesDirectory

白昼怎懂夜的黑 提交于 2020-08-10 01:19:48
问题 I have a .mp4 video saved in Firebase and I want to save it to the .cachesDirectory . I want to make sure it is saved and tried to use a do-try block but it wouldn't accept it: No calls to throwing functions occur within 'try' expression. How else can I check to see if the file was successfully saved to the .cachesDirectory ? let fbStr = "https://firebasestorage.googleapis.com/v0/b/myApp.appspot.com/o/abcd%277920FHqFBkl7D6j%2F-MC65EFG_qT0KZbdtFhU%2F48127-8C29-4666-96C9-E95BE178B268.mp4?alt