Iphone 正在尝试从照片库将图像保存到ipad应用程序包中 -(iAction)保存图像{ NSMutableArray*dictWords=[[NSMutableArray alloc]initWithObjects:“老虎”,“猫”,“玫瑰”,“大象”,“老鼠在找奶酪”,“风筝”,“汽车”,“飞机”,“芒果”,“水果从树上掉下来”,“山”,“鸟在飞”,“冰屋”,“这座房子是用木头建造的”,“香蕉”,“彩虹”,“火车”,“爸爸喝果汁”,“伞”“山羊”、“猫跳得高”、“狗跑得快”、“公共汽车”、“女孩在哭”、“星星”、“海豚”、“男孩在踢足球”、“玻璃里装满了水”、“船”、“降雪”、“鬼”、“兔子”、“西瓜”、“蜘蛛人”、“恐龙”、“米老鼠”、“猴子坐在树上”、“孔雀”、“闪电”、“母鸡下蛋”、“零”); NSString*path=[[NSBundle mainBundle]pathForResource:[youSaid text]的类型:@“png”inDirectory:@“Image”]; NSMutableDictionary*dict=[[NSMutableDictionary alloc]init]; 对于(int i=0;i
示例代码Iphone 正在尝试从照片库将图像保存到ipad应用程序包中 -(iAction)保存图像{ NSMutableArray*dictWords=[[NSMutableArray alloc]initWithObjects:“老虎”,“猫”,“玫瑰”,“大象”,“老鼠在找奶酪”,“风筝”,“汽车”,“飞机”,“芒果”,“水果从树上掉下来”,“山”,“鸟在飞”,“冰屋”,“这座房子是用木头建造的”,“香蕉”,“彩虹”,“火车”,“爸爸喝果汁”,“伞”“山羊”、“猫跳得高”、“狗跑得快”、“公共汽车”、“女孩在哭”、“星星”、“海豚”、“男孩在踢足球”、“玻璃里装满了水”、“船”、“降雪”、“鬼”、“兔子”、“西瓜”、“蜘蛛人”、“恐龙”、“米老鼠”、“猴子坐在树上”、“孔雀”、“闪电”、“母鸡下蛋”、“零”); NSString*path=[[NSBundle mainBundle]pathForResource:[youSaid text]的类型:@“png”inDirectory:@“Image”]; NSMutableDictionary*dict=[[NSMutableDictionary alloc]init]; 对于(int i=0;i,iphone,cocoa-touch,xcode,ipad,Iphone,Cocoa Touch,Xcode,Ipad,示例代码 -(IBAction)saveImage{ NSMutableArray *dictWords= [[NSMutableArray alloc]initWithObjects:@"TIGER",@"CAT", @"ROSE", @"ELEPHANT",@"MOUSE IS LOOKING FOR THE CHEESE",@"KITE",@"CAR",@"AEROPLANE",@"MANGO",@"FRUITS ARE FALLING FROM THE TREE",@"MO
-(IBAction)saveImage{
NSMutableArray *dictWords= [[NSMutableArray alloc]initWithObjects:@"TIGER",@"CAT", @"ROSE", @"ELEPHANT",@"MOUSE IS LOOKING FOR THE CHEESE",@"KITE",@"CAR",@"AEROPLANE",@"MANGO",@"FRUITS ARE FALLING FROM THE TREE",@"MOUNTAIN",@"BIRDS ARE FLYING",@"IGLOO",@"THIS HOUSE IS BUILT OF WOODS",@"BANANA",@"RAINBOW",@"TRAIN",@"DADDY DRINKS JUICE",@"UMBRELLA",@"GOAT",@"CAT JUMPS HIGH",@"DOG RUNS FAST",@"BUS",@"GIRL IS CRYING",@"STARS",@"DOLPHIN",@"BOYS ARE PLAYING FOOTBALL",@"GLASS IS FULL OF WATER",@"SHIP",@"SNOWFALL",@"GHOST",@"RABBIT",@"WATERMELON",@"SPIDERMAN",@"DINOSAUR",@"MICKEY MOUSE",@"MONKEY IS SITTING ON A TREE",@"PEACOCK",@"LIGHTNING",@"HEN LAYS EGGS",nil];
NSString *path=[[NSBundle mainBundle] pathForResource:[youSaid text] ofType:@"png" inDirectory:@"Image"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
for (int i=0 ; i<[assets count]; i++) {
if (i<[dictWords count]) {
[dict setObject:[[[assets objectAtIndex:i] defaultRepresentation] url] forKey:[NSString stringWithFormat:@"%@",[dictWords objectAtIndex:i]]];
NSLog(@"diccount:%d",[dict count]);
}
}
NSURL *imageurl = [dict objectForKey:[youSaid text]];
//NSLog(@"text:%@",[youSaid text]);
//Getting asset from url
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
//Setting asset image to image view according to the image url
[imageview setImage:[UIImage imageWithCGImage:iref]];
youSaid.text = [NSString stringWithFormat:@"%@",imageurl];
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Error, cant get image - %@",[myerror localizedDescription]);
};
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:imageurl resultBlock:resultblock failureBlock:failureblock];
UIImage *image=[[UIImage alloc]initWithContentsOfFile:path];
NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", youSaid.text]]; //add our image to the path
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the image
NSLog(@"image saved");
}
@end
这段代码对我有用,试试看也许对你有帮助
- (void) openPhotoLibrary {
NSLog(@"openPhotolibrary");
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
if (self.picker != nil) {
NSLog(@"releasing self.picker...");
[self.picker release];
}
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//self.picker.allowsImageEditing = YES;
[self.picker presentModalViewController:self.picker animated:YES];
self.picker.delegate = self;
[[[CCDirector sharedDirector] openGLView] addSubview:self.picker.view];
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)currentPicker {
NSLog(@"imagePickerControllerDidCancel");
// hide the self.picker if user cancels picking an image.
[currentPicker dismissModalViewControllerAnimated:YES];
self.picker.view.hidden = YES;
[self.picker.view removeFromSuperview];
}
- (void)imagePickerController:(UIImagePickerController *)currentPicker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[self saveImage:image withImageName:@"myPhoto"];
}
//saving an image
- (void)saveImage:(UIImage*)image withImageName:(NSString*)imageName {
NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; //add our image to the path
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
NSLog(@"image saved");
}
谢谢..:)Neet**将uiimage从photolibrary保存到捆绑包** (无效)imagePickerController:(UIImagePickerController*)PickerDidFinishPickingImage:(UIImage*)图像编辑信息:(NSDictionary*)编辑信息 { } (iAction)saveimg:(id)发送方{ } (iAction)pic*kers:(id)发送方{
}*嗨,克里斯蒂娜,你是否检查UIImage*图像是否为零?图像数据是否为零?我认为为零,这就是问题所在。我在从一个图像视图到另一个图像获取图像时非常困惑,你能告诉我对不起,你不能指定我代码中的更改吗?请…你是从图像视图获取图像吗?下面我的ans是save im照片库中的年龄。我也从照片库中提取我的图像并保存到应用程序包中,但没有任何用处。只需查看我的代码并告诉我必须在哪里进行更改,但它是用于照片而不是视频
-(IBAction)PhotoLibraryButtonClicked:(id)sender{
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
}
else{
[self displaysorceError];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//[self.popoverrcontroller dismissPopoverAnimated:true];
//[popoverrcontroller release];
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if([mediaType isEqualToString:(NSString *)kUTTypeImage]){
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// UIImage *rote = [image rotateInDegrees:219.0f];
img.image = image;
if(newMedia)
UIImageWriteToSavedPhotosAlbum(image, nil,nil, nil);
}else if([mediaType isEqualToString:(NSString *)kUTTypeImage]){
//not available vidio
}
}
-(IBAction)saveImageIn:(id)sender{
NSData *imageData = UIImagePNGRepresentation(img.image);
NSFileManager *fileMan = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@" %d.png",img.image]];
[fileMan createFileAtPath:fullPathToFile contents:imageData attributes:nil];
UIAlertView *alt = [[UIAlertView alloc]
initWithTitle:@"Thank You"
message:@"Image Save In Directory"
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alt show];
[alt release];
}
[self dismissModalViewControllerAnimated:YES];
imgview =[[UIImageView alloc]initWithFrame:CGRectMake(30, 30, 100, 100)];
imgview.image =image;
[self.view addSubview:imgview];
[imgview setUserInteractionEnabled:YES];
NSData *imageData = UIImageJPEGRepresentation(imgview.image,1.0);
NSFileManager *fileMan = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"deepu22%d.jpg",imgview.image]];
[fileMan createFileAtPath:fullPathToFile contents:imageData attributes:nil];
UIAlertView *alt = [[UIAlertView alloc]
initWithTitle:@"Thank You"
message:@"Image Save In Directory"
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alt show];
picker =[[UIImagePickerController alloc]init];
picker.delegate=self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];