【问题标题】:How to get correct photos path?如何获得正确的照片路径?
【发布时间】:2013-06-14 06:51:33
【问题描述】:
-(void) SaveScreenImage{
    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image= UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData* data =  UIImagePNGRepresentation ( image );
    UIImage* pngImage = [UIImage imageWithData:data];
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

    UIGraphicsEndImageContext();
}

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(NSString *)contextInfo
{
    UIImage *myImageView = image;
    NSLog(@"%@",contextInfo);

    NSString *message;
    NSString *title;
    if (!error) {
        title = NSLocalizedString(@"restore successful", @"");
        message = NSLocalizedString(@"restore to album libaray", @"");
    } else {
        title = NSLocalizedString(@"restore failure", @"");
        message = [error description];
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                    message:message
                                                   delegate:nil
                                          cancelButtonTitle:NSLocalizedString(@"nice", @"")
                                          otherButtonTitles:nil];
    [alert show];
    [alert release];

    //send contents to weixin
    WXMediaMessage *weixinmessage = [WXMediaMessage message];
    [weixinmessage setThumbImage:myImageView];

    WXImageObject *ext = [WXImageObject object];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"];
    ext.imageData = [NSData dataWithContentsOfFile:filePath];


//added media information
weixinmessage.mediaObject = ext;
SendMessageToWXReq* req = [[[SendMessageToWXReq alloc] init]autorelease];
req.bText = NO;
req.message = weixinmessage;
req.scene = _scene;

[WXApi sendReq:req];
}

【问题讨论】:

  • 这是什么语言?怎么了?你想要什么?
  • iOS,我想从快照中获取正确的照片。
  • 第一步:复制当前画面。 step 2:获取正确的照片形式相册。step 3:发送消息到微信通讯工具。

标签: ios cocoa-touch path photo


【解决方案1】:

除了使用 UIImageWriteToSavedPhotosAlbum,你可以使用 UIImagePNGRepresentation 或 UIImageJPEGRepresentation 来获取一个 NSData 对象,你可以直接应用到 WX 的东西上,不需要通过文件系统来回。

【讨论】:

    猜你喜欢
    • 2011-09-02
    • 1970-01-01
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 2013-01-10
    • 2017-08-11
    相关资源
    最近更新 更多