Ios 如何获得正确的照片路径?
您可以使用UIImageWriteToSavedPhotosAlbum或UIImagePNGRepresentation来获取NSData对象,而不必使用UIImageWriteToSavedPhotosAlbum,您可以直接将其应用于WX内容,而无需通过文件系统来回查看。这是什么语言?怎么了?你想要什么?iOS,我想要从快照中获取正确的照片。步骤1:复制当前屏幕。步骤2:从相册中获取正确的照片。步骤3:向微信通讯工具发送消息。Ios 如何获得正确的照片路径?,ios,cocoa-touch,path,photo,Ios,Cocoa Touch,Path,Photo,您可以使用UIImageWriteToSavedPhotosAlbum或UIImagePNGRepresentation来获取NSData对象,而不必使用UIImageWriteToSavedPhotosAlbum,您可以直接将其应用于WX内容,而无需通过文件系统来回查看。这是什么语言?怎么了?你想要什么?iOS,我想要从快照中获取正确的照片。步骤1:复制当前屏幕。步骤2:从相册中获取正确的照片。步骤3:向微信通讯工具发送消息。 -(void) SaveScreenImage{ UIGr
-(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];
}