- (void)saveImageToDocumentsDirectory:(int)imageNo :(NSMutableArray *)mimageArray :(imageList *)mimageList
{
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSDictionary *dict=[mimageArray objectAtIndex:imageNo];
NSString *image1Path;
NSString *imageName;
NSData *data2;
UIImage *image = [UIImage imageNamed:@"imageName"];
data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0)];
[data2 writeToFile:image1Path atomically:YES];
NSLog(@"THIS IS IMAGE1 DATA: %@",data2);
NSLog(@"THIS IS IMAGENAME: %@",imageName);
NSLog(@"THIS IS IMAGE1 PATH: %@",image1Path);
}
New to Objective C and stuck on this problem where I can't retrieve data from an image I capture.
目标C的新手,并坚持这个问题,我无法从我捕获的图像中检索数据。
I'm trying to capture an image from my device's camera and save it to my directory in my application users caches file.
我正在尝试从设备的相机中捕获图像并将其保存到我的应用程序用户缓存文件中的目录中。
The logs display the correct imageName and image1Path but when I log the data2 I just get <> , so there is no data for the image capture.
日志显示正确的imageName和image1Path,但是当我记录data2时,我得到<>,因此没有用于图像捕获的数据。
I have tried a version where I retrieve and save data from a url to the caches directory and that works but I just can't get it to work with a image captured from my device's camera.
我已经尝试了一个版本,我检索并将数据从网址保存到缓存目录,这是有效的,但我无法让它与我的设备的相机捕获的图像一起工作。
1 个解决方案
#1
0
Try below line of code for converting image to NSData:-
尝试下面的代码行将图像转换为NSData: -
NSData * data2 = UIImagePNGRepresentation(image);
#1
0
Try below line of code for converting image to NSData:-
尝试下面的代码行将图像转换为NSData: -
NSData * data2 = UIImagePNGRepresentation(image);