While saving a PNG image using NSData writetofile saves corrupted data on the iphone disk
- by jAmi
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.