While saving a PNG image using NSData writetofile saves corrupted data on the iphone disk

Posted by jAmi on Stack Overflow See other posts from Stack Overflow or by jAmi
Published on 2010-04-30T12:26:16Z Indexed on 2010/04/30 12:47 UTC
Read the original article Hit count: 233

Filed under:
|

I have a number of images (PNG,GIF and JPG) in my Application Resource Bundle. I want some images to be saved in my Documents Directory so i use :

    imgPath=[documentsDirectoryPath stringByAppendingPathComponent:@"myImage.png"];

    if (![fileMgr fileExistsAtPath:imgPath]) {

    [[fileMgr contentsAtPath:[[NSBundle mainBundle] pathForResource:@"myImage"ofType:@"png"]] writeToFile:imgPath atomically:NO];

}

This saves an Image file on my desired Path but this file has an Extra 300 bytes (of maybe junk data) in it which results in a corrupted image... Am i doing something wrong here?

This works in the simulator but on the real device the image has some extra 300 bytes. Also a GIF image gets copied nicely and works but this problem occurs for PNG image.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk