2010-03-19 175 views
0

我试图将UIImageView图像保存为PNG文件,然后使用该文件作为GLTexture。 我遇到了麻烦,当我尝试在模拟器中运行我的代码时,XCode说它成功了,但模拟器崩溃而没有错误消息。有人可以帮我弄这个吗? 这里是我的代码:使用UIImagePNGRepresentation需要帮助

NSString *dataFilePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Picture.png"]; 

    NSData *imageData = UIImagePNGRepresentation(imageView.image); 
    [imageData writeToFile:dataFilePath atomically:YES]; 

    // Load image into texture 
    loadTexture("Picture.png", &Input, &renderer); 
+0

确保左上角的构建配置设置为Debug(例如“Simulator -3.0 | Debug”),并执行** Build> Build and Debug **。然后执行** Run> Console **来查看您的控制台。这应该会显示你的错误信息。 – Tom 2010-03-19 04:06:36

+0

也检查dataFilePath和imageData ...他们中的任何一个NULL? Path是否有有效的字符串? – 2010-03-19 04:34:34

+0

当我运行Build&Debug并查看控制台时,我发现问题在于我的“Picture.png”文件未找到。我怎样才能让我的UIImageView保存到我可以在我的应用程序中使用的png文件中? – user297073 2010-03-19 05:09:29

回答

-1

试试这个:

NSString *dataFilePath = [[NSBundle mainBundle] pathForResource:@"Picture" ofType:@"png"]; 
+0

我试过了,但是我收到了这个错误信息“断言失败:(CGImage),函数loadTexture,文件程序收到信号:”SIGABRT“。” 这是我的代码://保存图片 NSString * dataFilePath = [[NSBundle mainBundle] pathForResource:@“Picture”ofType:@“png”]; NSData * imageData = UIImagePNGRepresentation(imageView.image); \t \t [imageData writeToFile:dataFilePath atomically:YES]; //将图像加载到纹理中 loadTexture(“Picture.png”,&Input,&renderer); 它崩溃的线: CGImageRef CGImage = [UIImage imageNamed:[NSString stringWithUTF8String:name]]。 rt_assert(CGImage); – user297073 2010-03-19 15:58:33

+1

iOS应用程序无法在自己的捆绑包内编写代码。 – 2013-05-14 23:05:20

1

您的回复Metalmi来看,它看起来像你不给我们您正在编译的实际代码。如果你真的在做你看起来像是在做的事情,那么你正试图将数据写入你的应用程序的捆绑包,这将失败,因为你不允许这样做。您能否向我们提供您正在尝试执行的确切代码?