PNG不以编程方式复制

时间:2016-05-24 20:44:45

标签: ios objective-c nsdata

这是我无法回答/解决的问题的扩展。所以我决定尝试使用复制和粘贴命令来解决这种情况。但是,当我尝试复制所选的图像时,它不允许我粘贴它,菜单不会弹出以允许粘贴,只有复制出现,我认为这意味着它不会复制到粘贴板。我就是这样的地方:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *file = stickers2[indexPath.item];

    NSLog (@"%d",indexPath.item);
    NSLog (@"%@ FILE STRING",file);
    NSString *sticker = [file stringByReplacingOccurrencesOfString:@".png" withString:@""];
    NSLog (@"%@ STICKER STRING",sticker);

        imageItem = [UIImage imageNamed:sticker];
    NSError* error = nil;
    UIPasteboard *pb = [UIPasteboard generalPasteboard];
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:sticker ofType:@"png"];

    NSLog(@"%@ IS THE IMAGE PATH!", imagePath);
    NSData *data = [NSData dataWithContentsOfFile:imagePath options:0 error: &error];
    [pb setData:data forPasteboardType:@"public.jpeg"];

    if (data == nil)
    {
        NSLog(@"Failed to read file, error %@", error);
    }


    NSLog(@"%@", pb);
    NSLog(@"%@",data);


    if (delegate != nil) [delegate didSelectSticker:sticker];{
        NSLog(@"HAHHAHHA");
    };
    NSLog (@"%@",file);

    [self dismissViewControllerAnimated:YES completion:nil];
}

的NSLog:

2016-05-25 13:42:58.320 [4469:1236352] 28
2016-05-25 13:42:58.320 [4469:1236352] stickersend28@2x.png FILE STRING
2016-05-25 13:42:58.321 [4469:1236352] stickersend28@2x STICKER STRING
2016-05-25 13:42:58.336 [4469:1236352] /var/containers/Bundle/Application/F60DE305-F6F2-4562-BD66-CCB7FA9992AE/SomeApp.app/stickersend28@2x.png IS THE IMAGE PATH!
2016-05-25 13:42:58.384 [4469:1236352] <UIPasteboard: 0x12e8c3520>

//This Continues for a lot longer than posted.
2016-05-25 13:42:58.388 4469:1236352] <89504e47 0d0a1a0a 00000004 43674249 50002006 2cb87766 0000000d 49484452 000000d2 000000d2 08060000 003f999e 42000009 f7694343 50494343 2050726f 66696c65 0000ad96 09d81c1e aaa8ca38 239207eff70c 3f000000 0049454e 44ae4260 82>
2016-05-25 13:42:58.403[4469:1236352] HAHHAHHA
2016-05-25 13:42:58.403[4469:1236352] stickersend28@2x.png

ChatView.m

- (void)paste:(NSIndexPath *)indexPath
{
    UIImage *sticker = [UIPasteboard generalPasteboard].image;
    NSLog(@"CALLED IT");
    NSLog(@"%@",sticker);
    NSData* imageData = UIImageJPEGRepresentation(sticker, 1);
    NSMutableDictionary *item = [NSMutableDictionary dictionary];
    [item setValue:imageData forKey:(NSString*)kUTTypeJPEG];
    [[UIPasteboard generalPasteboard] addItems:[NSArray arrayWithObject:item]];

        NSLog(@"%@ IMAGEDATA",imageData);
        NSLog(@"%@ITEM",item);

}




  //NSLog

       2016-05-26 13:00:30.906 [5297:1473004] CALLED IT
    2016-05-26 13:00:30.907 [5297:1473004] <UIImage: 0x1270c3600>, {105, 105}
    2016-05-26 13:00:30.907 [5297:1473004] <UIPasteboard: 0x127204130>

ImageData and Item return Walls of Numbers.

0 个答案:

没有答案