Objective c Mac开发人员-映像I/O
我的第一个问题 我正在尝试创建一个简单的应用程序,它从一个位置拍摄一张照片,并将其放在桌面上。我遇到的问题是以下错误:Objective c Mac开发人员-映像I/O,objective-c,xcode,Objective C,Xcode,我的第一个问题 我正在尝试创建一个简单的应用程序,它从一个位置拍摄一张照片,并将其放在桌面上。我遇到的问题是以下错误: 2012-10-27 10:49:16.405 saveFile[3271:303] +[__NSCFConstantString scheme]: unrecognized selector sent to class 0x7fff73c01e38 2012-10-27 10:49:16.406 saveFile[3271:303] +[__NSCFConstantS
2012-10-27 10:49:16.405 saveFile[3271:303] +[__NSCFConstantString scheme]: unrecognized selector sent to class 0x7fff73c01e38
2012-10-27 10:49:16.406 saveFile[3271:303] +[__NSCFConstantString scheme]: unrecognized selector sent to class 0x7fff73c01e38
在这一行:
CGImageRef imageItself = CGImageSourceCreateImageAtIndex(myImageSource, 0, NULL);
下面是实际代码:
头文件:
#import <Cocoa/Cocoa.h>
//NSOpenPanel = use finder
NSOpenPanel *openPanel;
//URL is the directory
NSURL* theDoc;
//Don't allow bottom button to malfunction by being clicked early.
bool topButtonClicked = NO;
@interface saveFileAppDelegate : NSObject <NSApplicationDelegate>
- (IBAction)moveFile:(id)sender;
- (IBAction)chooseFile:(id)sender;
@property (nonatomic, retain) IBOutlet NSTextField *label;
@property (assign) IBOutlet NSWindow *window;
@end
在这里
我设法把它修好了。我把它抽象了一点,并且尽可能地延长了每个方法,这样我就可以一步一步地看到它。我想我会为任何一个偶然发现我的问题的人发布我的修正
以下是.m中移动文件部分的结束代码:
- (IBAction)moveFile:(id)sender {
if (topButtonClicked == YES) {
//Take in picture
CFURLRef CFURLReftheDoc = (__bridge CFURLRef)theDoc;
CGImageSourceRef myImageSource = CGImageSourceCreateWithURL(CFURLReftheDoc, NULL);
//Create a reference to the image itself, take in the image read, which image (only one, so 0), and additional options.
CGImageRef imageItself = CGImageSourceCreateImageAtIndex(myImageSource, 0, NULL);
//Save picture to desktop
//Store desktop directory.
NSString *path = [@"~/Desktop/public.png" stringByExpandingTildeInPath];
NSURL *NSURLdesktopURL = [[NSURL alloc] initFileURLWithPath:path];
NSLog(@"%@",NSURLdesktopURL);
//store where I want to save, the type of file I expect to save, number of images to save, any additional options.
CGImageDestinationRef whereToSave = CGImageDestinationCreateWithURL((__bridge CFURLRef)NSURLdesktopURL, kUTTypeJPEG, 1, NULL);
// NSLog(@"%@",whereToSave);
//Begin final preperations, pull altogether desktop URL, the image read in before, and additional options.
CGImageDestinationAddImage (whereToSave, imageItself, NULL);
//Finalize (write the file)
CGImageDestinationFinalize(whereToSave);
//CGImageDestinationRef saveImageToDesktop (CFURLRef desktop, CFStringRef jpeg, size_t count, CFDictionaryRef NULL);
}
else{
/* open an alert with an OK button */
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Stop it."];
[alert runModal];
}
}
@end
- (IBAction)moveFile:(id)sender {
if (topButtonClicked == YES) {
//Take in picture
CFURLRef CFURLReftheDoc = (__bridge CFURLRef)theDoc;
CGImageSourceRef myImageSource = CGImageSourceCreateWithURL(CFURLReftheDoc, NULL);
//Create a reference to the image itself, take in the image read, which image (only one, so 0), and additional options.
CGImageRef imageItself = CGImageSourceCreateImageAtIndex(myImageSource, 0, NULL);
//Save picture to desktop
//Store desktop directory.
NSString *path = [@"~/Desktop/public.png" stringByExpandingTildeInPath];
NSURL *NSURLdesktopURL = [[NSURL alloc] initFileURLWithPath:path];
NSLog(@"%@",NSURLdesktopURL);
//store where I want to save, the type of file I expect to save, number of images to save, any additional options.
CGImageDestinationRef whereToSave = CGImageDestinationCreateWithURL((__bridge CFURLRef)NSURLdesktopURL, kUTTypeJPEG, 1, NULL);
// NSLog(@"%@",whereToSave);
//Begin final preperations, pull altogether desktop URL, the image read in before, and additional options.
CGImageDestinationAddImage (whereToSave, imageItself, NULL);
//Finalize (write the file)
CGImageDestinationFinalize(whereToSave);
//CGImageDestinationRef saveImageToDesktop (CFURLRef desktop, CFStringRef jpeg, size_t count, CFDictionaryRef NULL);
}
else{
/* open an alert with an OK button */
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Stop it."];
[alert runModal];
}
}
@end