Note that there are some explanatory texts on larger screens.

plurals
  1. POUIImagePickerController delegate method not re-saving/overwriting new pictures taken
    primarykey
    data
    text
    <p>I'm using a simple implementation of UIImagePickerController to take a picture and save it to my app directory. I"m running into problems with didFinishPickingMediaWithInfo, where I retrieve the image from the info, convert it into NSData using UIImageJPEGRepresentation, and then save it to a file. Problem is, the NSData object appears never to be overwritten, so the first time I take a picture it saves the picture just fine, but any subsequent pictures are not saved, because when I redisplay the image located at the filePath I'm saving it to, it's always the very first picture I took.</p> <p>I have NSLog statements right now printing out the hash of the UIImage and of the NSData object I'm saving the image to. The UIImage hash changes each time, but the NSData hash is exactly the same all the time...shouldn't that change too? </p> <p>My code is below. Note that everything not declared in the delegate method below is a global var that isn't causing me any trouble (at least they don't seem to be).</p> <pre><code>-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); documentsDirectory = [paths objectAtIndex:0]; filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileNameString]; NSData *imageData = UIImageJPEGRepresentation(image, 0.5f); // imageData = [NSData dataWithData:UIImageJPEGRepresentation(image, 0.5f)]; [imageData writeToFile:filePath atomically:YES]; [self dismissModalViewControllerAnimated:YES]; } </code></pre> <p>When I get rid of the NSData object entirely and replace all instances of </p> <pre><code>imageData </code></pre> <p>with</p> <pre><code>UIImageJPEGRepresentation(image, 0.5f) </code></pre> <p>I still have the same problem, namely that the hash of UIImageJPEGRepresentation(image, 0.5f) is always the same, even though the hash of the UIImage it takes as a parameter always changes.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload