0
votes

I capture a image of webview that playing a flash. Because I want to show this image and use the IKSaveOptions to save the image .but I found the path of image is nil, Now I want to get the path of image , How to do ? my code: NSString *path = [[NSBundle mainBundle] pathForResource: ?? ofType:??]; NSURL *url = [NSURL fileURLWithPath: path]; then I use the url to show the image in the imageview,but Now I didn't get the path ,Thanks a lot!


thanks a lot. Now I think that the NSBundle is not my option. But I want to show the image of capturing it from a webview showing a flash. I can show it in a imagecell, but show in the imageview ,I use the code:

[imageView setImage:image imageProperties: mImageProperties];

and the mImageProperties come from ahead of the document of you take me the ImageKit documentation, the name is "Viewing an Image in an Image View" ,and in there the mImageProperties is the properties of image . code is :

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

still ues the url of the image, if I couldn't use the NsBundle , How I can do to get the properties of the image, by the way, I have already get the image of the capturing webview of showing a flash. code :

NSBitmapImageRep *imageRep = [webView bitmapImageRepForCachingDisplayInRect:[webView frame]]; [webView cacheDisplayInRect:[webView frame] toBitmapImageRep:imageRep]; NSImage *image = [[NSImage alloc] initWithSize:[webView frame].size]; [image addRepresentation:imageRep];

2

2 Answers

3
votes

Okay, you are confusing a lot of things here. First off, IKSaveOptions does not save an imnage. It is a mechanism for presenting an interface to the user about the options the want for saving, but it does not actually save the file anywhere. To save the file you use the underlying CGImage mechanisms, as described in the ImnageKit documentation. I think if you read the example code there it will also be clear where the path to the saved file is.

Now, onto the second issue. You would never use pathForResource:ofType to get it. That gets resources that are in your application bundle. In other words, things that are a part of your application, that you include with it at build time. You should NEVER modify your bundle contents after build, aside from being complicated, it will invalidate codesigned applications. Instead you should probably use either CGImage or NSImage to read it in.

0
votes

ok, I have the answer. 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);
}