Converting GIF images to nsdata

2019-01-29 06:01发布

问题:

I have an iPhone application that needs to save an image onto the database in BLOB format. The problem is that if the image is in .gif format then it cannot be converted to NSDATA format and hence i am not been able to save that onto the database in BLOB format.

What should I do?

Please help with some code..

Thanks in advance Joy

回答1:

A gif image can be converted into NSData...Here's the code snippet:

NSString *pathForGif = [[NSBundle mainBundle] pathForResource: @"gifFile" ofType: @"gif"];

NSData *gifData = [NSData dataWithContentsOfFile: pathForGif];

NSLog(@"Data: %@", gifData);

The log looked something like this:

    Data: <47494638 39616400 6400f7ff 001f3546 a71a2568 7a85bacd caa8a99a a8ada689 969599a8 
 a7684430 282e3496 9b97b5bd b69aa69b 47596667 7679dbe9 eb076997 efd9ce0f 2532c9d6 cc908875
 d7dddb86 8c89c9c7 bac8cdc9 c9764fc9 bcadd38f 69c8141e 6b554eb0 8e72a99a 8c566a74 e8ecedef
 e8d48b77 6c733526 56636871 6555eed6 b8cdb294 ... 76797acc d9d76667 66ba6743 f2a30f88 948b5657
 58999688 a95737fa d05edad9 cbd08658 aebbca37 55660516 248d6c55 acb7b847 5356dae8 dca95944
 d8dceb4a 322c4646 45344956 353f4677 847aaa64 449a5436 020d13d7 ccb96c2c 17b7ab9a 8c9ba196>


标签: nsdata gif