-1
-(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];
}
4

1 回答 1

0

Instead of using UIImageWriteToSavedPhotosAlbum, you can use UIImagePNGRepresentation or UIImageJPEGRepresentation to get an NSData object you can apply directly to the WX stuff, no need to go through the file system and back.

于 2013-06-15T14:51:50.250 回答