开发者

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

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 atomi开发者_开发问答cally: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.


You could try using NSFileManagers -(BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error method to see if you get better results.

If you're trying to view the saved PNG on your Mac, you may have issues since Xcode will convert your PNGs to iPhone optimized versions when it's building your app.

Here is more info on the optimizations performed, and here is Apple's Technical Q&A for undoing the optimizations so you can view the image on your desktop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜