将GIF图像转换为nsdata [英] Converting GIF images to nsdata

查看:220
本文介绍了将GIF图像转换为nsdata的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序,需要将图像以BLOB格式保存到数据库中.问题是,如果图像为.gif格式,则无法将其转换为NSDATA格式,因此我无法将其以BLOB格式保存到数据库中.

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.

我该怎么办?

请帮助一些代码.

先谢谢了 欢乐

推荐答案

可以将gif图像转换为NSData ...下面是代码段:

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);

日志看起来像这样:

    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>

这篇关于将GIF图像转换为nsdata的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆