ein Image einsetzen mittels replaceCharactersInRange

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • ein Image einsetzen mittels replaceCharactersInRange

    es steht geschrieben:

    You can embed graphics or other attachments in text in either of two ways: programmatically or
    directly through user actions. In the programmatic approach, you can add graphic objects using the
    NSText method replaceCharactersInRange:withRTFD: or through a more specific method defined
    by a subclass.

    nun habe ich einen Text und ein Image in tiff-Format und kann nicht das Image an den Text anhängen - es kommt halt nur den Text in die resultierende rtfd-Datei hinein, nicht aber das Image.

    mit dem Text mace ich das folgende:


    Quellcode

    1. NSText *theText=[[NSText alloc] init];
    2. [theText replaceCharactersInRange:NSMakeRange (0,0) withRTF:[theAttributedString RTFFromRange:NSMakeRange(0,[theAttributedString length]) documentAttributes:theDict]];
    3. [theText writeRTFDToFile:theFileName atomically:NO];


    mit dem Image habe ich etliches ausprobiert, bislang ohne Erfolg

    ob da jemand weiss, wie man die Sache handhaben soll?
    Gruss aus Russland :)
  • RE: ein Image einsetzen mittels replaceCharactersInRange

    ich habe es doch gelöst:


    Quellcode

    1. NSTextAttachment *theAttachment;
    2. NSFileWrapper *theWrapper = [[[NSFileWrapper alloc] initWithPath:graphFileName] autorelease];
    3. theAttachment = [[[NSTextAttachment alloc] initWithFileWrapper:theWrapper] autorelease];
    4. NSAttributedString *theThing=[NSAttributedString attributedStringWithAttachment:theAttachment];
    5. NSText *theText=[[NSText alloc] init];
    6. [theText replaceCharactersInRange:NSMakeRange (0,0) withRTF:[theAttributedString RTFFromRange:NSMakeRange(0,[theAttributedString length]) documentAttributes:dict]];
    7. [theText replaceCharactersInRange:NSMakeRange ([theAttributedString length],0) withRTFD:[theThing RTFDFromRange:NSMakeRange(0,[theThing length]) documentAttributes:dict]];
    8. [theText writeRTFDToFile:theFileName atomically:NO];
    Gruss aus Russland :)