nsdata

Load image from url in iPhone, only if small

你离开我真会死。 提交于 2019-11-30 15:42:39
I'm using initWithContentsOfURL of NSData to load an image from a url. However, I don't know the size of the image beforehand, and I would like to the connection to stop or fail if the response exceeds a certain size. Is there a way to do this in iPhone 3.0? Thanks in advance. You can't do it directly via NSData however NSURLConnection would support such a thing by loading the image asynchronously and using connection:didReceiveData: to check how much data you have received. If you go over your limit just send the cancel message to NSURLConnection to stop the request. Simple example:

Audio recorded using Audio Queue Services to data

╄→尐↘猪︶ㄣ 提交于 2019-11-30 14:42:44
I want to transmit voice from one iPhone to another. I have established connection between two iPhones using TCP and I have managed to record voice on the iPhone and play it using Audio Queue Services. I have also managed to send data between the two iPhones. I do this by sending NSData packages. My next step is to send the audio data to the other iPhone as it is being recorded. I believe I should do this in the AudioInputCallback . My AudioQueueBufferRef is called inBuffer and it seems that I want to convert the inBuffer->mAudioData to NSData and then send the NSData to the other device and

“The operation couldn’t be completed. (Cocoa error 512.)”

泪湿孤枕 提交于 2019-11-30 14:22:28
I have this code, which should be working perfectly, but I can't udnerstand why it isn't: +(NSString *)writeImageToFile:(UIImage *)image { NSData *fullImageData = UIImageJPEGRepresentation(image, 1.0f); NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Images/"]; NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL isDirectory = NO; BOOL directoryExists = [fileManager fileExistsAtPath:path isDirectory:&isDirectory]; if (directoryExists) { NSLog(@"isDirectory: %d", isDirectory); } else { NSError *error = nil; BOOL success = [fileManager

Swift - Create a GIF from Images and turn it into NSData

元气小坏坏 提交于 2019-11-30 13:30:26
问题 This might be an amateur question, but although I have searched Stack Overflow extensibly, I haven't been able to get an answer for my specific problem. I was successful in creating a GIF file from an array of images by following a Github example: func createGIF(with images: [NSImage], name: NSURL, loopCount: Int = 0, frameDelay: Double) { let destinationURL = name let destinationGIF = CGImageDestinationCreateWithURL(destinationURL, kUTTypeGIF, images.count, nil)! // This dictionary controls

Get the data from NSURLSession DownloadTaskWithRequest from completion handler

爱⌒轻易说出口 提交于 2019-11-30 13:04:04
So I'm having hard time understanding something. This are the things I understand about NSURSession : Generally , I have 2 options for (as far as I know) DataTask(e.x dataTaskWithRequest) And DownloadTask(e.x DownloadTaskWithRequest ) - Using their delegate method , or use the completion handler , Can't do both. I have managed to receive DATA using dataTaskWithRequest like this : let request = NSMutableURLRequest(URL: dataSourceURL!) request.HTTPMethod = "POST" let postString = "lastid=\(id)" request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding) let task = NSURLSession

How can a moderately sized memory allocation fail in a 64 bit process on Mac OS X?

我是研究僧i 提交于 2019-11-30 12:33:35
I'm building a photo book layout application. The application frequently decompresses JPEG images into in-memory bitmap buffers. The size of the images is constrained to 100 megapixels (while they usually do not exceed 15 megapixels). Sometimes memory allocations for these buffers fail: [[NSMutableData alloc] initWithLength:] returns nil . This seems to happen in situations where the systems's free physical memory approaches zero. My understanding of the virtual memory system in Mac OS X was that an allocation in a 64 bit process virtually (sic) can't fail. There are 16 exabyte of address

UIImage created from CGImageRef fails with UIImagePNGRepresentation

假如想象 提交于 2019-11-30 12:10:35
I'm using the following code to crop and create a new UIImage out of a bigger one. I've isolated the issue to be with the function CGImageCreateWithImageInRect() which seem to not set some CGImage property the way I want. :-) The problem is that a call to function UIImagePNGRepresentation() fails returning a nil. CGImageRef origRef = [stillView.image CGImage]; CGImageRef cgCrop = CGImageCreateWithImageInRect( origRef, theRect); UIImage *imgCrop = [UIImage imageWithCGImage:cgCrop]; ... NSData *data = UIImagePNGRepresentation ( imgCrop); -- libpng error: No IDATs written into file Any idea what

What is NSConcreteData, and where is it defined?

懵懂的女人 提交于 2019-11-30 11:38:54
The following code: [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]] returns an instance of NSConcreteData as opposed to NSData (which I expected!). What does NSConcreteData represent, exactly, and why is it being returned instead of an instance of NSData? Further, where is this class defined? XCode is complaining that it hasn't been defined, but I don't know what I should include in order to get the class. Any help appreciated! Fraser Speirs The Foundation framework uses class clusters in certain areas to provide a common interface to various classes. What this means is that

Loading takes a while when i set UIImage to a NSData with a url.

天涯浪子 提交于 2019-11-30 09:44:30
问题 NSData *imageUrl = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[self.content objectAtIndex:indexPath.row] valueForKey:@"imageUrl"] ]]; cell.thumbnailImageView.image=[UIImage imageWithData:imageUrl]; this is how i use imageUrl to load them into UIImage but it takes a while to load and the program seems like it crashed or entered to an infinite loop. How can i make the content of UIImage with url but faster? 回答1: use sdwebimage and down load the library file from here the few steps you

UIImage to raw NSData / avoid compression

牧云@^-^@ 提交于 2019-11-30 09:05:58
问题 I have my own image downloader class, it holds a queue and downloads images one (or a certain amount) at a time, writes them to the cache folder and retrieves them from the cache folder when necessary. I also have a UIImageView subclass to which I can pass a URL, through the image downloader class it will look if the image already exists on the device and show it if it does, or download and show it after it finished. After an image finishes downloading I do the following. I create a UIImage