【问题标题】:how to get the path and url of the temp image?如何获取临时图像的路径和网址?
【发布时间】:2010-10-07 08:58:59
【问题描述】:

我捕获了播放 Flash 的 webview 图像。因为我想展示这张图片,并使用IKSaveOptions来保存图片。但是我发现图片的路径是nil,现在我想获取图片的路径,怎么办? 我的代码: NSString *path = [[NSBundle mainBundle] pathForResource: ?? ofType:??]; NSURL *url = [NSURL fileURLWithPath: path]; 然后我使用url在imageview中显示图像,但是现在我没有得到路径,非常感谢!


非常感谢。现在我认为 NSBundle 不是我的选择。但我想显示从显示闪光灯的 web 视图中捕获它的图像。我可以在 imagecell 中显示它,但在 imageview 中显示,我使用代码:

[imageView setImage:image imageProperties: mImageProperties];

并且 mImageProperties 来自你带我的 ImageKit 文档的文档,名称是“Viewing an Image in an Image View”,其中 mImageProperties 是 image 的属性。代码是:

mImageProperties = (NSDictionary*)CGImageSourceCopyPropertiesAtIndex(isr, 0, (CFDictionaryRef)mImageProperties);

仍然使用图像的url,如果我不能使用 NsBundle ,我该如何获取图像的属性,顺便说一下,我已经获得了显示flash的捕获webview的图像.代码:

NSBitmapImageRep *imageRep = [webView bitmapImageRepForCachingDisplayInRect:[webView frame]]; [webView cacheDisplayInRect:[webView frame] toBitmapImageRep:imageRep]; NSImage *image = [[NSImage alloc] initWithSize:[webView frame].size]; [图片添加表示:imageRep];

【问题讨论】:

    标签: cocoa


    【解决方案1】:

    好的,你在这里混淆了很多东西。首先,IKSaveOptions 不保存图像。它是一种向用户提供有关要保存的选项的界面的机制,但它实际上并不将文件保存在任何地方。要保存文件,请使用底层 CGImage 机制,如 ImnageKit documentation 中所述。我想如果您阅读那里的示例代码,您也会清楚保存文件的路径在哪里。

    现在,进入第二个问题。你永远不会使用 pathForResource:ofType 来获取它。这将获取应用程序包中的资源。换句话说,作为应用程序一部分的东西,在构建时包含在其中。您应该切勿在构建后修改您的包内容,除了复杂之外,它还会使代码签名的应用程序无效。相反,您可能应该使用 CGImage 或 NSImage 来读取它。

    【讨论】:

      【解决方案2】:

      好的,我有答案。 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 表示。
      猜你喜欢
      • 1970-01-01
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多