Cocoa 如何获取临时映像的路径和url?
我拍摄了一张播放flash的webview图像。因为我想显示这个图像并使用IKSaveOptions来保存图像。但是我发现图像的路径是nil,现在我想获取图像的路径,怎么办? 我的代码: NSString*路径=[[NSBundle mainBundle]路径用于资源:??,类型:??]; NSURL*url=[NSURL fileURLWithPath:path]; 然后我使用url在imageview中显示图像,但是现在我没有得到路径,非常感谢Cocoa 如何获取临时映像的路径和url?,cocoa,Cocoa,我拍摄了一张播放flash的webview图像。因为我想显示这个图像并使用IKSaveOptions来保存图像。但是我发现图像的路径是nil,现在我想获取图像的路径,怎么办? 我的代码: NSString*路径=[[NSBundle mainBundle]路径用于资源:??,类型:??]; NSURL*url=[NSURL fileURLWithPath:path]; 然后我使用url在imageview中显示图像,但是现在我没有得到路径,非常感谢 非常感谢。现在我认为NSBundle不是我的
非常感谢。现在我认为NSBundle不是我的选择。但是我想展示从一个显示flash的网络视图中捕获它的图像。我可以在imagecell中显示,但在imageview中,我使用以下代码: [imageView setImage:image imageProperties:mImageProperties] mImageProperties来自于前面的文档youtakemeimagekit文档,名称是“在图像视图中查看图像”,其中mImageProperties是图像的属性。代码是: mImageProperties=(NSDictionary*)CGImageSourceCopyPropertiesAtIndex(isr,0,(CFDictionaryRef)mImageProperties) 仍然使用图像的url,如果我不能使用NsBundle,我如何获得图像的属性,顺便说一下,我已经获得了显示flash的捕获webview的图像。代码: NSBitmapImageRep*imageRep=[webView bitmapImageRepForCachingDisplayInRect:[webView框架]]; [webView cacheDisplayInRect:[webView框架]toBitmapImageRep:imageRep]; NSImage*image=[[NSImage alloc]initWithSize:[webView frame].size];
[image addRepresentation:imageRep] 好吧,你把这里的很多事情弄糊涂了。首先,IKSaveOptions不保存imnage。它是一种向用户提供界面的机制,用于向用户显示要保存的选项,但实际上并不将文件保存到任何位置。要保存文件,请使用底层CGImage机制,如ImnageKit中所述。我认为,如果您阅读那里的示例代码,也会很清楚保存文件的路径在哪里
NSImage *theimage = [[NSImage alloc] initWithSize:tmpRect.size];
[theimage addRepresentation:imageRep];
CGImageSourceRef isr = CGImageSourceCreateWithData((CFDataRef)[theimage TIFFRepresentation], NULL);
CGImageRef image = NULL;
if (isr)
{
image = CGImageSourceCreateImageAtIndex(isr, 0, NULL);
if (image)
{
mImageProperties = (NSDictionary*)CGImageSourceCopyPropertiesAtIndex(isr, 0, (CFDictionaryRef)mImageProperties);
}
CFRelease(isr);
}
if (image)
{
[imageView setImage:image imageProperties:mImageProperties];
CGImageRelease(image);
}
现在,谈谈第二个问题。您永远不会使用pathForResource:of type来获取它。获取应用程序包中的资源。换句话说,是应用程序的一部分,在构建时包含在其中的内容。您不应该在构建之后修改捆绑包内容,除了复杂之外,它将使代码签名的应用程序无效。相反,您可能应该使用CGImage或NSImage来读取它。好的,您在这里混淆了很多东西。首先,IKSaveOptions不保存imnage。它是一种向用户提供界面的机制,用于向用户显示要保存的选项,但实际上并不将文件保存到任何位置。要保存文件,请使用底层CGImage机制,如ImnageKit中所述。我认为,如果您阅读那里的示例代码,也会很清楚保存文件的路径在哪里 现在,谈谈第二个问题。您永远不会使用pathForResource:of type来获取它。获取应用程序包中的资源。换句话说,是应用程序的一部分,在构建时包含在其中的内容。您不应该在构建之后修改捆绑包内容,除了复杂之外,它将使代码签名的应用程序无效。相反,您可能应该使用CGImage或NSImage来读取它。好的,我有答案。 NSBitmapImageRep*imageRep=[webView bitmapImageRepForCachingDisplayInRect:tmpRect]; [webView cacheDisplayInRect:tmpRect toBitmapImageRep:imageRep]
NSImage *theimage = [[NSImage alloc] initWithSize:tmpRect.size];
[theimage addRepresentation:imageRep];
CGImageSourceRef isr = CGImageSourceCreateWithData((CFDataRef)[theimage TIFFRepresentation], NULL);
CGImageRef image = NULL;
if (isr)
{
image = CGImageSourceCreateImageAtIndex(isr, 0, NULL);
if (image)
{
mImageProperties = (NSDictionary*)CGImageSourceCopyPropertiesAtIndex(isr, 0, (CFDictionaryRef)mImageProperties);
}
CFRelease(isr);
}
if (image)
{
[imageView setImage:image imageProperties:mImageProperties];
CGImageRelease(image);
}
好的,我有答案。
NSBitmapImageRep*imageRep=[webView bitmapImageRepForCachingDisplayInRect:tmpRect];
[webView cacheDisplayInRect:tmpRect toBitmapImageRep:imageRep]
NSImage *theimage = [[NSImage alloc] initWithSize:tmpRect.size];
[theimage addRepresentation:imageRep];
CGImageSourceRef isr = CGImageSourceCreateWithData((CFDataRef)[theimage TIFFRepresentation], NULL);
CGImageRef image = NULL;
if (isr)
{
image = CGImageSourceCreateImageAtIndex(isr, 0, NULL);
if (image)
{
mImageProperties = (NSDictionary*)CGImageSourceCopyPropertiesAtIndex(isr, 0, (CFDictionaryRef)mImageProperties);
}
CFRelease(isr);
}
if (image)
{
[imageView setImage:image imageProperties:mImageProperties];
CGImageRelease(image);
}
无需通过NSImage,因为NSBitmapImageRep有一个直接从中获取TIFF表示的实例方法。无需通过NSImage,因为NSBitmapImageRep有一个直接从中获取TIFF表示的实例方法。