nsdata

Compare two images to check if they are same

萝らか妹 提交于 2019-12-10 11:43:26
问题 I got a Profile view with a ImageView where a User can change their picture. I'm saving my old & new image to compare them. I would like to know if they're the same, so if they are I dont need to push the new one to my Server. I tried this but it doesn't really work: + (NSData*)returnImageAsData:(UIImage *)anImage { // Get an NSData representation of our images. We use JPEG for the larger image // for better compression and PNG for the thumbnail to keep the corner radius transparency float i

Find Character String In Binary Data

早过忘川 提交于 2019-12-10 03:26:26
问题 I have a binary file I've loaded using an NSData object. Is there a way to locate a sequence of characters, 'abcd' for example, within that binary data and return the offset without converting the entire file to a string? Seems like it should be a simple answer, but I'm not sure how to do it. Any ideas? I'm doing this on iOS 3 so I don't have -rangeOfData:options:range: available. I'm going to award this one to Sixteen Otto for suggesting strstr. I went and found the source code for the C

Convert a JSON NSData to NSDictionary

佐手、 提交于 2019-12-10 03:04:29
问题 I'm using an API service of a web service and it is written in their description that they send JSON data wich also matches in my opinion with the response I get from it. Here a part of it which I got from the NSURLConnection-Delegate (connection didReceiveData: (NSData *) data) and converted in a NSString using: NSLog(@"response: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); Here the snippet: {"scans": { "Engine1“: { "detected": false, "version": "1.3.0.4959",

Working with NSData in swift

跟風遠走 提交于 2019-12-09 16:16:06
问题 So I've figured out how to extract NSData in swift but i'm getting confused with regards to setting it: var testBytes : [Byte] = [0x14, 0x00, 0xAB, 0x45, 0x49, 0x1F, 0xEF, 0x15, 0xA8, 0x89, 0x78, 0x0F, 0x09, 0xA9, 0x07, 0xB0, 0x01, 0x20, 0x01, 0x4E, 0x38, 0x32, 0x35, 0x56, 0x20, 0x20, 0x20, 0x00] var msgData = NSData(bytes: testBytes, length: testBytes.count) println("\(msgData)") var length : Int = testBytes.count var out: NSInteger = 0 let ptr = UnsafePointer<UInt8>(msgData.bytes) var bytes

NSData dataWithContentsOfFile returning null

只愿长相守 提交于 2019-12-09 14:38:38
问题 I am trying to fetching a JSON file which exist in my xcode resources using this code -(void)readJsonFiles { NSString *str=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"classes.json"]; NSLog(@"Path: %@", str); NSData *fileData = [NSData dataWithContentsOfFile:str]; NSLog(@"Data: %@", fileData); SBJsonParser *parser = [[SBJsonParser alloc] init] ; NSDictionary *jsonObject = [parser objectWithData:fileData]; NSLog(@"%@", jsonObject); } path return me this link of file

Swift get NSData of a video from photos library

拜拜、爱过 提交于 2019-12-09 13:40:03
问题 Im using UIImagePickerController to select a video from my library. I need to extract the NSData of my video file. Im using the following operation to select a video from my library but my data appears to be nil however my AVPlayer plays the video from the resulting NSURL so I know problem is not with the NSURL. How can I extract the NSData of my selected video file? func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { let

How to pack struct in NSData? [duplicate]

≯℡__Kan透↙ 提交于 2019-12-09 06:05:34
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Send and receive NSData via GameKit I have struct which consists of int variable and 2 float pointers (arrays). How can I pack this struct ib NSData and later unpack it? 回答1: You can pack the structure using dataWithBytes method pf NSData : struct aStruct { /* Implementation */ }; //Struct variable aStruct exampleStruct; // pack the struct into an NSData Object NSData *myData = [NSData dataWithBytes:

NSData dataWithContentsOfURL

偶尔善良 提交于 2019-12-08 22:29:16
问题 I have this method for button click (download). The problem is that it is terminating due to an exception: [Session started at 2011-03-14 13:06:45 +0530.] 2011-03-14 13:06:45.710 XML[7079:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString isFileURL]: unrecognized selector sent to instance 0x62b8' -(IBAction) download { UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:@"http://ws.cdyne.com/WeatherWS/Images

Behavior of NSData initWithBytesNoCopy:length:freeWhenDone:

老子叫甜甜 提交于 2019-12-08 22:04:46
问题 I want to have a fix length mutable content shared data buffer and that is how do I create it: void *buffer = malloc(length); // initialize buffer content NSData *sharedData = [[NSData alloc] initWithBytesNoCopy:buffer length:length freeWhenDone:YES] What happen if I modify buffer after I created a NSData from it? Will NSData reflect the change I did to buffer ? I can guaranty that sharedData will not get dealloc when I want to modify buffer . This is how I actually want to use it: void *my

iPhone: How to Write an Image to Disk in the App Directories

喜你入骨 提交于 2019-12-08 13:18:44
问题 I am working on an iPhone project in which I need save camera images to disk and file but the code below fails: (************ -(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; imgglobal =imageView.image; NSString *newFilePath = [NSHomeDirectory() stringByAppendingPathComponent: @"~/Users/abc/Library