公式アカウントからの投稿が始まります

Cについては、全くの素人です。

「Xcodeプログラミング大全」という書籍を参考に、開発を進めているのですが、行き詰まってしまったので、質問させて下さい。
ImageKitを使ったイメージブラウザを作成して、取り込んだ画像を別名で別の場所に保存するプログラムを作成しています。

前半部は文字数の関係で省略します。
ボタンをクリックして画像を保存します。

- (IBAction)myButton:(id)sender;
{
// imagebrowserに保存した画像を順番に処理
for(int i=0; i< [myImages count]; i++){
NSData *data = nil;
NSString *errorDescription;
//NSPasteboard *pasteboard = [myImages objectAtIndex:i];

if([[[myImages objectAtIndex:i] types] containsObject:NSFilenamesPboardType])
data = [[myImages objectAtIndex:i] dataForType:NSFilenamesPboardType];
if(data){
NSArray *filenames = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:kCFPropertyListImmutable format:nil errorDescription:&errorDescription];
for(int j=0;j< [filenames count];j++){
//NSLog(@"%@",[filenames objectAtIndex:j]);

NSBitmapImageRep* bitmap = [myImages objectAtIndex:i];
// 画像保存
NSData* outdata = [bitmap representationUsingType:NSPNGFileType properties:[NSDictionary dictionary]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
NSString* path = [NSString stringWithFormat:@"%@/test.png",[paths objectAtIndex:0], nil];

[outdata writeToFile:path atomically:YES];
/
}
}
}
}
@end

エラーは発生しないのですが、コンソールに「[MyImageObject types]: unrecognized selector sent to instance 0xf722590」と表示されます。
また、画像は全く保存されません。

どなたか、ご教授をお願いします。

A 回答 (1件)

こんにちわ



ざっと見た限りで回答してみますが、コンソールに出力されている内容はunrecognized selectorですからインスタンスにセレクタがない、と言っているのだと思います。該当箇所は明示されている通り[MyImageObject types]なので、実装をみると

if([[[myImages objectAtIndex:i] types] containsObject:NSFilenamesPboardType])

のif文中ではないかと思います。ここで[myImages objectAtIndex:i]オブジェクトに対してtypesセレクタの存在を想定しているのは、[myImages objectAtIndex:i]がNSPasteboardクラスのインスタンスであるからだと想像しますが認識は合っていますか?

しっかりコードを読み込んでいないのでわかりにくいのですが、コードの下の方に

NSBitmapImageRep* bitmap = [myImages objectAtIndex:i]

とあり、[myImages objectAtIndex:i]をNSBitmapImageRepとして取得しています。NSBitmapImageRepにtypesセレクタはないと思います。コードの前半と後半で同じオブジェクトに対して2種類の型を想定しているように見えますがいかがでしょうか?
    • good
    • 0
この回答へのお礼

ご指摘ありがとうございました。

[myImages objectAtIndex:i]imageRepresentation]とすることでパスを取得できました。

ありがとうございました。

お礼日時:2010/02/19 17:29

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!